0

I want to delete this from a string:

[QUOTE=*] * [/QUOTE]

.* kan be anything

Can anyone please provide a pattern that I can use?

4
  • I need to use the text after that quoted stuff Commented Jul 31, 2010 at 10:34
  • which part do you need to use? the first * or the second one? Commented Jul 31, 2010 at 10:40
  • I hope you know that BBCode is not a regular language and thus cannot be parsed with regular expression. Commented Jul 31, 2010 at 10:45
  • I need the part after [/QUOTE] and that seems to work unless there's a <br /> inside de quote tags. Then it doesn;t recognize it as the same pattern... Commented Jul 31, 2010 at 12:43

2 Answers 2

3
$string = preg_replace('/\[QUOTE=[^\]]*\].*\[\/QUOTE\]/', '', $string);
Sign up to request clarification or add additional context in comments.

3 Comments

seems to work unless there's a <br /> inside de quote tags. Then it doesn;t recognize it as the same pattern
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.
not sure (yet) what an s modifier is, but it worked :) thnx again
2

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].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.