سؤال

I have text stored in my forum database with some incompatible such as the following:

Some text with [COLOR="red"]colored text[/COLOR] and [SIZE="7"]Big fonts[/SIZE] while "This double quote" is not matched

What I want is a regex that match any double quotes " " with any string inside them while those double quotes are inside the square bracket [ ] of the bbcode.

I need this to be able to fix those bbcodes by stripping the double quotes. The regex implementation is going to be using PHP.

هل كانت مفيدة؟

المحلول 2

You may be looking for something like this:

$code= 'Some text with [COLOR="red"]colored text[/COLOR] and [SIZE="7"]Big fonts[/SIZE] while "This double quote" is not matched';

preg_match_all('/\[.*?="(\w+)"\]/', $code, $matches, PREG_PATTERN_ORDER);
for ($i = 0; $i < count($matches[1]); $i++) {
    echo $matches[1][$i]."\n";
}

DEMO:
https://ideone.com/LEZHgx

نصائح أخرى

Try this:

\[\w+=("[^"]*")\]

It matches square bracket, alphanumerics, equal sign, quoted string, close square bracket. Capture group 1 will contain the quoted part.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top