aspose file tools*
The moose likes Java in General and the fly likes How to retrieve numeric value from HTML tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to retrieve numeric value from HTML tags" Watch "How to retrieve numeric value from HTML tags" New topic
Author

How to retrieve numeric value from HTML tags

Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
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

Joined: May 03, 2008
Posts: 4543
    
    5

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/

luck, db
There are no new questions, but there may be new answers.
Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to retrieve numeric value from HTML tags