pattern help...

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
welsh_sponger
Forum Newbie
Posts: 14
Joined: Fri Feb 03, 2006 7:46 am

pattern help...

Post by welsh_sponger »

Hello.

Im trying to match a pattern and extract some values... im having some problems...

This is what i have at the moment...

Code: Select all

$page = file_get_contents("http://www....");

preg_match( "/[\w\s]+[\w\s]+[\w\s]+[\w\s]+[\w\s](\d{3}\s+)(\d+\.\d\s+)[\d+\.\s+)]+(\d\.\d\s+)(\d)/i", $page, $matches);
Im trying to match from this string...

41001 2006 02 20 11 220 3.0 6.0 1.6 9

My code is producing the result, 220 3.0 1.6 9, which is correct! however the values are constanly changning, and sometimes the 6.0 value above becomes 'MM' which obviously messes up the pattern. What do i need to do to the pattern to allow for both possiblities...?

I also need to verify that the string starts with the first value of 41001 exactly, how can this be done?

Thanks very much...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

#^\s*41001\s+(?:\d+\s+){4}(\d+(?:\.\d*)?)\s+(\d+(?:\.\d*)?)\s+(?:\d+(?:\.\d*)?|[a-z]+)\s+(\d+(?:\.\d*)?)\s*$#im
:?:
Post Reply