tags:

views:

33

answers:

2

My HTML looks like this:

<td class="main"><b>Product Weight  (2.83 lbs in 1 container)</b></td>

I need to get the value 2.83 from the HTML.

Need help with the regex.

I have this:

    Pattern p = Pattern.compile(

  "<td\\sclass=\"main\"><b>Product\\sWeight\\s\\s((?:\\d+\\.)?\\d+ \\w{3})");

But doesn't seem to be working.

Am I missing an escape or something?

Update

If the brackets are an issue, do I just do ( or on the inner brackets also?

+2  A: 

Looks like you're missing an escape on the literal parentheses.

Cory Petosky
+1  A: 

For getting specific html-tags I recommend HTML-parsers over Regex. You could for example use this html-parser.

Ham
Good instinct, but the OP isn't trying to parse HTML, just scrape data that happens to be surrounded by tags.
Etaoin
+1 on htmlparser, you may also want to look at [jsoup](http://jsoup.org)Also see the many answers on SO warning against trying to use regex to parse HTML.
Stephen P
You're right, if it this single data extraction is everything to be done, setting up a parser would be a bit overkill.
Ham