Page 1 of 1

Need help finding and replacing text for "{#ANY_TEXT#}"

Posted: Tue Sep 15, 2009 9:57 am
by andrewlwong
Hi,

I need your expert help. I'm trying to find a regular expression to replace all text between quotes "{#ANY_TEXT#}"

For example, if I have string like "This is a test {#ANY_TEXT#} string". I need to replace everything starting from {#...#} with another value. For example, If I want to make it blank, then end result should be "This is a test string". There could be several instances of this.

Thanks in advance for your help.

Andrew

Re: Need help finding and replacing text for "{#ANY_TEXT#}"

Posted: Tue Sep 15, 2009 10:02 am
by prometheuzz
Try this:

Code: Select all

$text = "This is a test {#ANY_TEXT#} string";
echo preg_replace('/{#(?:(?!#}).)*+#}/s', 'REPLACEMENT', $text);