Reputation: 39
Currently learning PHP with RegEx and I want to extract the DAX value from a website.
Got the website source with file_get_contents
and then cleaned up the tags with strip_tags
.
The block that contains the string i want is this one:
Dax5.502-2,4%
but i just need the value 5.502
The regex code I have so far is '/@Dax\d.\d\d\d[+-]\d,\d[%]$/'
But it doesnt work. can anyone tell me how to do this correctly.
Thanks :)
Upvotes: 0
Views: 1333
Reputation: 197732
You do not need to use a regular expression to parse the formatted string, sscanf
Docs looks like a more fitting way to parse the float value (Demo):
$str = 'Dax5.502-2,4%';
sscanf($str, 'Dax%f', $value);
echo $value; # 5.502
Upvotes: 0
Reputation: 324630
/^Dax([0-9].[0-9]{3})/
With that (which is all you need), your result will be the number.
Upvotes: 1