regex help

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

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

regex help

Post by SidewinderX »

ok i have never used regex before...i read the "crash corse", googled for a bit and expermented on my own and ive got no where.

im trying to extract a value from a string

Code: Select all

input type='hidden' name='pageLastName' value='- O.a.D_Side'> <input type='hidden' name='pageFirstName' value=' HELLPOINTNER '> <input type='hidden' name='resultPageNumber' value='2'> <input type='hidden' name='currentSelection' value='0'> <input type='hidden' name='numPerPage' value='10'> <input type='hidden' name='type' value='contains'> <input type='hidden' name='deepSearch' value=''> &nbsp; </TD> <td align='right'> <input type='submit'
the string is longer but i shortened the ending for viewing purposes (the begining is the exact same). The line that constains the information i want to extract is the first line.

Code: Select all

input type='hidden' name='pageLastName' value='- O.a.D_Side'>
Escentially i want to extract "- O.a.D_Side" but the name dosnt remain constant. The name can be any variation of 16 characters including all alpahnumeric characters (A-Z, a-z, 0-9) and underscores, spaces and periods.

Could someone (using my example) show me how to do this?

Thanks in advanced
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

preg_match('#name=\s*(["\'])?pageLastName\\1[^>]*?value=(["\'])?(.*?)\\2#si',$text,$match);
echo $match[3];
Post Reply