Blankman
Blankman

Reputation: 267200

How to extract product weight from this HTML

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?

Upvotes: 0

Views: 76

Answers (2)

Ham Vocke
Ham Vocke

Reputation: 2994

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

Upvotes: 1

Cory Petosky
Cory Petosky

Reputation: 12656

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

Upvotes: 2

Related Questions