0

I have following html content part, and I want to get the value

-7326630261683062897:1196341531039871985

from all http content. There is only one unique point that is id javax.faces.ViewState.

How can I get the value? What kind of regex do I have to use?

<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" 
value="-7326630261683062897:1196341531039871985" autocomplete="off" />
2
  • 3
    Read How can I parse a HTML string in Java? Commented Aug 7, 2014 at 18:56
  • 2
    I would caution you against using regex for any HTML tag. Considering you're using Java, there's probably already a parser for HTML. Check out the link above Commented Aug 7, 2014 at 18:57

2 Answers 2

0
Pattern p = Pattern.compile("value=\"(-)*[\\d]+:[\\d]+\"");
Matcher m = p.matcher(html);
while(m.matches()){
    String s = m.group();
    s = s.subString(7, s.size()-2);
}

At the point after the substring call, s should contain just what you want.

Sign up to request clarification or add additional context in comments.

2 Comments

where to use id="javax.faces.ViewState". There are many value="" statements in html content
Use a parser if you want all the values. It will do a much better job and less head ache for you
0

You can use the following regex:

id="javax\.faces\.ViewState".*value="(.*?)"

Working demo

MATCH 1
1.  [84-124]    `-7326630261683062897:1196341531039871985`

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.