Reputation: 2742
I am having problems trying to extract the correct value from a text
I want to extract 14.50
from the following text (which is the last decimal number in the string).
string
<span class="ob-pricedetails">Price:</span> $57.71<span style="color: #666666; font-size: 12px;">(£37.61)</span><br/><span style="font-size: 11px; color: #000000;">Shipping (UK):</span>$14.50
I have been trying to use the following regex
regex
(?<=Shipping \(UK\):<\/span>£|$)(.*)
which returns the following result for some strange reason
57.71<span style="color: #666666; font-size: 12px;">(£37.61)</span><br/><span style="font-size: 11px; color: #000000;">Shipping (UK):</span>$14.50
What am I doing wrong? any help would be appreciated.
Upvotes: 0
Views: 68
Reputation: 14691
This would work:
preg_match('/Shipping \(UK\):<\/span>$([0-9]+\.[0-9]+)/', $html, $matches);
Of course you should listen to everyone suggesting yo use a DOM parser instead of regular expressions.
Upvotes: 2