Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

preg replace help needed



9:24 pm on Dec 2, 2008 (gmt 0)

5+ Year Member

I'm trying to remove all bbcode tags in my forum post with the following:

$patterns[0] = "/\[.+\]/i";
$replacements[0] = "";
$postText = preg_replace($patterns, $replacements, $postText);

However when running into the following it will match the entire string below (and thereby remove it):


Instead it should have matched tag1 then tag2 then... and so on.

Any input on what I can do to accomplish this without trying to match each individual tag?

Thanks in advance.


7:44 am on Dec 3, 2008 (gmt 0)

5+ Year Member

it seems i need to change the pattern from greedy to ungreedy by using the ? quantifier or /U.


8:25 am on Dec 3, 2008 (gmt 0)

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Yes, you're right - add ? after the +

Featured Threads

Hot Threads This Week

Hot Threads This Month