Would like to extract an amount in the following string:
£5000 per Night - 1 bedroom - Serviced Apartment
Any idea on how to do it using preg match all ?
I’m using this pattern:
preg_match_all("|£(\d)|U",$string,$matches);
but it only fetches 5 instead of 5000
what if it’s £15,000 could be extract it with the comma ?
thx for helping,
Stephane
Use
\d+instead of\d. Otherwise, it’ll only match a single digit.+means ‘one or more’.(For more details on how repetition works in regular expressions, see this page.)
An expression that allows commas as well, and makes sure that they aren’t in weird spots (e.g.
,500):