thebadbad Posted June 12, 2009 Share Posted June 12, 2009 Yeah, my definition was a bit loose. characters that are within the pattern need to be escaped (for the most part this is true.. but there are oddball exceptions.. but I digress) I can't imagine a case where you don't have to escape delimiters in the pattern. Or were you talking about characters in general? Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted June 12, 2009 Share Posted June 12, 2009 Nope, I am talking about delimiter characters in a pattern Consider the following for example: $str = 'Some text... <_FOO_> some more text <_BAR_> and yet again some more!'; $str = preg_replace('<<_[^_]+_>>', '<_XX_>', $str); // note there is no need to escape < and > inside the delimiters in this scenario... echo $str; // Output: Some text... <_XX_> some more text <_XX_> and yet again some more! This is admittedly a stupid (and rare) example. But it shows that under some circumstances, it might not require escaping. In this case, there is a caveat... there has to be matching opening and closing < and > characters inside the < > delimiters.. if there is a mismatch, then you'll probably need to escape (otherwise you'll get either 'Unknown modifier' or 'No ending matching delimiter' warnings). I personally advise against using opening / closing matching punctuation as delimiters (such as <...>, {...}, (...) or [....]). Too much confusion / trouble for what it's worth IMO. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 12, 2009 Share Posted June 12, 2009 Ah, thanks for enlightening me! Didn't know you could have nonidentical delimiters like < and >. But I agree, seems more confusing than necessary. I should probably just read a book, instead of keep bugging you Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted June 12, 2009 Share Posted June 12, 2009 I should probably just read a book, instead of keep bugging you lol no worries. Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted June 19, 2009 Share Posted June 19, 2009 thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.