Page 1 of 1

preg issue

Posted: Sat Feb 07, 2004 3:05 pm
by m3rajk
i have a quote set up i made that replaces the blockquote of html that's been deprecated. issue is that the preg replacement doesn't work on nested quotes. not quite sure why. if anyone can tell me why and help me fix it, i would appreciate that.current php preg search:[php # add quotes
$postcode=preg_replace('|\[/quote]|i', '<hr /></div>', $postcode);
$postcode=preg_replace('|\[quote(=(.*))(?U)]|i', '<div class="quote">Quote \2<hr />', $postcode);result can bee seen in this thread:http://www.findyourdesire.com/forums.php?fid=4&tid=13 (currently the last post has got a nested one)

thanx in advance for the help

ps- an aside. i have something else i'm doing and using sessions there. just as question since i'm not used to sessions, is my understanding that any session variable that gets registered i can access via $variable instead of $_SESSION['variable']?

Posted: Sat Feb 07, 2004 3:13 pm
by dodga
I think the problem is that RegEx tend to find the longest possible match.
Have a look at this page - which actually is for sed, but it uses the same RegEx :D
:arrow: http://www-106.ibm.com/developerworks/l ... -sed2.html

Look out for the "Regexp snafus"; should be pretty much the same situation as yours :wink:

Posted: Sat Feb 07, 2004 4:50 pm
by m3rajk
hmmm... volka i think isthe one who gave me the ?U trick for non-greedy. i don't see anything that helps fix it :(

Posted: Sat Feb 07, 2004 5:32 pm
by m3rajk
figured it out. just have ot changehow the non-greedy is signaled