Thread: regex problem
View Single Post
Old 05-30-2008, 11:16 PM   #4 (permalink)
delayedinsanity
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Have you tried using the s modifier? Depending on how you're feeding the data in to your regex, it may be a quick and dirty solution to your problem (the s modifier treats any string/block that the regular expression is traversing as a single line).

Outside of that, Salathe was sending you in the right direction. You can use \r, \n or \v to check for the possibility of newlines or vertical whitespace, just the same as you would use 0-9 to check for the letters 0-9, or _ to check for underscores, etc... you just have to incorporate them into the regex whereever you think there could eventually be one. Give it the option to find it. For example,

PHP Code:
$szTest = <<<EOF
/* this
is the
test */

booga!

/* more
new lines
in this
comment
*/
EOF;

$szTest preg_replace("~/\*(.*?\r?\n?)+\*/~"'booga!'$test);
echo 
$szTest
Outputs:

booga! booga! booga!
-m
delayedinsanity is offline  
Reply With Quote