I’m using the Google calculator to retrieve converted prices, a sample output is this:
{lhs: "9000 Euros",rhs: "12 721.5 U.S. dollars",error: "",icc: true}
Now I cannot use json_decode for this JSON string, I’ve tried it but it doesn’t work, so I’m using regex to retrieve the converted price in the rhs field.
I need to make the regex to be able to parse the number, not the currency name at all, just the number, however I have a problem with getting the price that includes a space in the field, my regex so far only gets 12, I cannot get the full thing 12 721.5.
/rhs\: "(\d+|\s+)/i
How can I do this without including the price name? Note the response may/may not include space in the converted price and also a period.
If you only want to extract out the number part, then your regex could be:
The
[...]square brackets are the appropriate syntax for the alternatives here (any combination of decimals and spaces).Edit: Missing decimals dot, and some more regex for verifying the “json” consistency.