Page 1 of 1

regex help

Posted: Fri Sep 23, 2005 7:26 pm
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

Posted: Fri Sep 23, 2005 7:32 pm
by feyd

Code: Select all

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