Jump to content


Photo

Need help with regex...


  • Please log in to reply
4 replies to this topic

#1 genericnumber1

genericnumber1
  • Members
  • PipPipPip
  • Advanced Member
  • 1,858 posts

Posted 11 October 2006 - 12:07 AM

Hey, I'm trying to pull some information from a string using regex, nothing TOO hard. I just figure I have my regex pattern wrong, hopefully that's what it is or I'm in the wrong forum. (this is of course not my real code, but it works the same way)

<?php
$r = 1;
$information = '

blah
//startcode1
$code = "blah
blah
blah
blah
";//endcode1
blah
';
?>
I'm trying to just pull out the part that starts with

//startcode1
$code = "

and ends with

";//endcode1

Here is my method...

<?php
preg_match('/(\/\/startcode'.$r.'\n\$code = )["\'](.*)["\'](;\/\/endcode'.$r.')/s', $information, $matches);
?>

yet when I print_r() the $matches, there is nothing.... help >.>?

#2 effigy

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

Posted 11 October 2006 - 02:54 AM

Try \r\n as opposed to just \n.

preg_match('%^//startcode' . $r. '\s+^\$code\s*=\s*"(.+?)";\s*//endcode' . $r . '%sm', $information, $matches);

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 genericnumber1

genericnumber1
  • Members
  • PipPipPip
  • Advanced Member
  • 1,858 posts

Posted 11 October 2006 - 03:23 AM

got it man! thanks! what is \r? :D

#4 effigy

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

Posted 11 October 2006 - 04:18 AM

A.K.A. CR or the Carriage return: more info.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 genericnumber1

genericnumber1
  • Members
  • PipPipPip
  • Advanced Member
  • 1,858 posts

Posted 11 October 2006 - 04:33 AM

thanks  ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users