Page 1 of 1

Please Help Me With This Regex

Posted: Wed Apr 20, 2011 1:02 pm
by Gicker
Hi there.

I am having problems getting a regex to work in PHP.

Here is the code:

Code: Select all

<?php
 
  $string = "[check=wisdom,13]You recall that Maesyn had mentioned he knew of a [i]genasi[/i] sage who would know something of a moderately powerful Primordial House called House Golaxad, of which the being in the crystal previously, Cozox, was a member of.  The genasi was said to reside in SkyClave, of which the scene through the window of the room in the portal seems to be, given your memory of the place when you traveled there to arrive at Restwell Keep and the Chaos Scar area of High Imaskar.[/check]";
 
  $string = preg_replace('/\[check=.+\[\/check\]/gi', "CHECK REMOVED", $string);
 
echo $string;
?>
I keep getting the error Warning: preg_replace(): Delimiter must not be alphanumeric or backslash. I have tried many variation, looked up online but I am completely stumped. Any help would be greatly appreciated.

Re: Please Help Me With This Regex

Posted: Fri Apr 22, 2011 9:06 pm
by ridgerunner
There are two problems with this code. 1.) The string has two double quotes which need to be escaped. and 2.) The regex has the 'g' modifier set. There is no 'g' modifier with PHP preg regexes. With these two fixes, your code runs fine.

Re: Please Help Me With This Regex

Posted: Sat Apr 23, 2011 4:50 am
by audrriean
oh it is important and i like this post.
Match.com Free Trial

Re: Please Help Me With This Regex

Posted: Sat Apr 23, 2011 7:02 am
by Gicker
ridgerunner wrote:There are two problems with this code. 1.) The string has two double quotes which need to be escaped. and 2.) The regex has the 'g' modifier set. There is no 'g' modifier with PHP preg regexes. With these two fixes, your code runs fine.
Wow, how I missed those double quotes, it's shameful :)

I didn't know about the g modifier though in php, thanks.