• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to retrieve numeric value from HTML tags

 
Jack Bush
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Java Specialists,

I would appreciate your advice on how to retrieve the employee id using regex from the following simple Java program without success:


However, below is the output which is not the employee number anticipated:

The employeeID of John is false

Thanks in advance,

Jack
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. matches(...) returns a boolean.
2. HTML isn't a regular grammar, so regex isn't the best tool. Use a HTML parser.

However, if all you want to do is obtain the only subsequence that consists entirely of digits, then the fact that the input String is valid HTML becomes irrelevant. Just replaceAll(...) non-digits with the empty String.

Useful references:
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replaceAll(java.lang.String, java.lang.String)
http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
http://docs.oracle.com/javase/tutorial/essential/regex/index.html
http://www.regular-expressions.info/
 
Jack Bush
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Darryl for your suggestion,

I will find a more suitable regex to do a partial search for the numeric substring in example even though html is the most effective tool to use in this case.

Jack
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic