Please Help Me With This Regex

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Gicker
Forum Newbie
Posts: 2
Joined: Wed Apr 20, 2011 12:42 pm

Please Help Me With This Regex

Post 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.
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: Please Help Me With This Regex

Post 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.
audrriean
Forum Newbie
Posts: 1
Joined: Sat Apr 23, 2011 4:45 am

Re: Please Help Me With This Regex

Post by audrriean »

oh it is important and i like this post.
Match.com Free Trial
Gicker
Forum Newbie
Posts: 2
Joined: Wed Apr 20, 2011 12:42 pm

Re: Please Help Me With This Regex

Post 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.
Post Reply