Jump to content


Photo

how to preg_match_all with single quotes


  • Please log in to reply
3 replies to this topic

#1 cgchris99

cgchris99
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 17 October 2006 - 03:06 PM

Need to parse out this piece of code...
-----------------------------------------------------------------
theForm.action = 'Browse.aspx?MyAction=632966656416040865';
        theForm.submit();
-----------------------------------------------------------------
What I need is the number after MyAction. But I can't get my code to work.  It seems to have trouble with either the single quote or the semicolon. Here is what I have coded

preg_match_all("#MyToken=(.*?)/';#s",$page,$myaction);

But this doesn't work.  What do I have wrong?

Thanks for any advice or help.




#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 17 October 2006 - 03:48 PM

MyToken should be MyAction and you don't need the forward slash.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 cgchris99

cgchris99
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 17 October 2006 - 06:11 PM

That's an oops on my part.  It actually is
preg_match_all("#MyAction=(.*?)/';#s",$page,$myaction);

But it still doesn't work.



#4 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 19 October 2006 - 02:18 AM

preg_match_all ( "!(?<=myaction=)\d+!si", $page, $myaction );

results will be in

$myaction[0];

I do it this way, so you only return the data you want, no need for more arrays!


me!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users