RE: Regex Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Hi, folks.   I'm having trouble with a simple regex.  I'm sure it's just
> something small that I'm missing but nothing I'm trying is working.
> 
> In an HTML file I have comments like this:
> 
> <!-- START PRINT -->
> various html crap here
> <!-- END PRINT -->
> 
> Here's the regex I'm using:
> 
> /<!-- START PRINT -->(.*?)<!-- END PRINT -->/
> 
> And then the call to preg_match_all():
> 
> preg_match_all($printable_reg, $str, $out);
> 
> It's been quite a while since I've worked with regular expressions so
> I'm not sure what the problem is.  The regex isn't throwing errors, it's
> just not matching the content located between the start print and end
> print comments.
> 
> Can anyone lend a hand or give some advice?

Hi Pablo,

At a (reasonable) guess, I'd say it's because you're not using the "s"
pattern modifier in your preg_match_all()? The "s" modifier forces your
regular expression to match new lines with the "." metacharacter.

Try:

preg_match_all("/<!-- START PRINT -->(.*?)<!-- END PRINT -->/s", $str,
$out);

http://php.planetmirror.com/manual/en/reference.pcre.pattern.modifiers.php

Hope this helps.

Much warmth,

Murray
---
"Lost in thought..."
http://www.planetthoughtful.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux