I am trying to extract a number followed by the word "metres" in a string. Some have a space between the number and word and some dont. Here is my expression:
preg_match("/([0-9]*)(\s?)metres/is", $desc, $m)
Not sure this is quite working though. It should match:
5 metres 5metres 500 metres 500metres
Any ideas?
Little_G
10:06 am on May 30, 2009 (gmt 0)
Hi,
This works for me,
/([0-9]+)\\s?metres/i
. I had to double escape the s, not sure why but it works.
Andrew
mehh
11:17 am on May 30, 2009 (gmt 0)
I had to double escape the s, not sure why but it works.
I think its because of double quotes (") so the '\s' get translated to just 's' before the regex is evaluated. So the regex above can be used or the double quotes can be switched for single.
henry0
11:28 am on May 30, 2009 (gmt 0)
if you are always looking for a few "metres" then you could be on the right track but did you consider that the non plural for example .75 or 1 "metre" does not have an "s"