tags:

views:

38

answers:

2

I want to delete this from a string:

[QUOTE=*] * [/QUOTE]

.* kan be anything

Can anyone please provide a pattern that I can use?

+3  A: 
$string = preg_replace('/\[QUOTE=[^\]]*\].*\[\/QUOTE\]/', '', $string);
Jhong
thanks! you're great! :D
Jay
Ha! Thanks... don't know about that. Feel free to mark my answer as accepted :-)
Jhong
seems to work unless there's a <br /> inside de quote tags. Then it doesn;t recognize it as the same pattern
Jay
It should work with <br />, but it will not match if newlines (\n) are present.add the 's' modifier to the end (after the final '/') to let it match over newlines. However, you might have to also make the ".*" ungreedy by adding a '?' after it.
Jhong
not sure (yet) what an s modifier is, but it worked :) thnx again
Jay
+2  A: 

Jhongs answer is perfect, it will leave you with the content from the both *'s.

However, if you need the parts separately you can make a small adjustment and add capturing groups like so:

if (preg_match('%\[QUOTE=([^\]]*)\](.*)\[/QUOTE\]%', $subject, $matches))
{
...
}

The *'s will be at $matches[1] and $matches[2].

Blizz