0

How would I get the "$0.00" in between this font tag?

<font color="#99002B">
$0.00
</font>

This is the only one on the page I want to get.

I really don't understand regex, so maybe someone could help whilst they answer too!

Thanks

EDIT: The $ sign isn't always there either. It might be, for example;

EUR 0,00 £ 4.44

3
  • What programming language are you using? Commented Aug 16, 2014 at 22:23
  • 1
    Are you looking to get the $0.00 or the #99002B value? Will you be wanting to get many other values for tags? Commented Aug 16, 2014 at 22:24
  • I'm using the PCRE library, so PHP. Commented Aug 16, 2014 at 22:24

3 Answers 3

0

You've asked for a regular expression here, but it's not the right tool for parsing HTML.

$doc = new DOMDocument;
$doc->loadHTML($html); // Load your HTML data

$xpath = new DOMXPath($doc);
$node  = $xpath->query("//font[@color='#99002B']")->item(0);
echo $node->nodeValue; //=> "$0.00"

Working Demo

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

Comments

0
/<font color="#99002B">\n?(.+[0-9]+\.[0-9]+)\n?<\/font>/

Working demo: https://regex101.com/r/ME7QqL/1

If there are some more spaces around use:

/<font color="#99002B">\s*(.+[0-9]+\.[0-9]+)\s*<\/font>/

Maybe you have to replace all "\n" by "" before it works - haven't tested.

1 Comment

PHP has no gmodifier.
0

https://regex101.com/r/hapFEQ/1

const pattern = /<font color="#99002B".*?>([\s\S]*?)<\/font>/i;
const match = `<font color="#99002B">
$0.00
</font>`.match(pattern);
const result = match ? match[1].trim() : '';
console.log(result);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.