Re: Re: Dynamic Regex

From: Date: Thu, 09 Jan 2003 06:06:46 +0000
Subject: Re: Re: Dynamic Regex
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-130874@lists.php.net to get a copy of this message
Made sense. Thanks for your help. Greg Beaver wrote:
hi Gerard, I didn't think you were complaining :) the problem is in [/url] $foo = '/\[url\]([a-z]+://.*?)\[/url\]/'; should be $foo = '/\[url\]([a-z]+://.*?)\[\/url\]/'; that "/" was ending the pattern, and so preg_* was trying to read "url\]/" as closing information, and probably giving an odd error about "u" not being appropriate that's why # worked, because there were no other # in the string. Hope that answers the question (properly this time!) Take care, Greg ----- Original Message ----- From: "Gerard Samuel" <gsam@trini0.org> To: "Greg Beaver" <greg@chiaraquartet.net> Cc: <php-general@lists.php.net> Sent: Thursday, January 09, 2003 12:24 AM Subject: Re: [PHP] Re: Dynamic Regex
What you suggested is what I was trying before. My original example was incorrect. Here is an good example for the variable holding the pattern -> $foo = '/\[url\]([a-z]+://.*?)\[/url\]/'; This pattern would not work, but if I change it to $foo = '#\[url\]([a-z]+://.*?)\[/url\]#'; It does work. Not complaining but just trying to figure out why the first version doesn't work for future references. Thanks Greg Beaver wrote:
Hi Gerard, all the preg_* functions require delimiters surrounding regular
     
expressions.
$foo = '\[this\](.*?)that'; should be by default: $foo = '/\[this\](.*?)that/'; the code you tried uses # as the delimiter instead of /, an option preg_* allows Take care, Greg -- phpDocumentor http://www.phpdoc.org "Gerard Samuel" <gsam@trini0.org> wrote in message news:3E1CC193.90605@trini0.org...
     
The example doesn't have to make sense, but Im looking for the correct syntax for $foo. I was trying -> $foo = '\[this\](.*?)that'; $bar = 'the other'; $str = preg_replace($foo, $bar, $other_string); But that doesn't work. I came across an example where the syntax of $foo is in -> $foo = '#\[this\](.*?)that#'; The second syntax of $foo works. I was wondering on the meaning of # in the string?? Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/
       
     
-- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/
-- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/

« previous php.general (#130874) next »