2

Can anyone please tell me what is wrong with this regex?

preg_match( "/\+?)\)(=.+?,.+?)?\](.+?)\[\/quote\](?!((.*?)\[\/quote\]))/s", $text, $match, null, $start);

It should be functioning (i've found it on a forum), but it throws an error: Warning: preg_match() [function.preg-match]: Compilation failed: unmatched parentheses at offset 3

I am guessing that something is wrong about the parantheses?

Thanks in advance, fischer

1
  • 1
    This regex is definitely broken. If you specify the intended result and the string to match regex against, we could try to provide a meaningful response. Jan 26, 2011 at 11:41

4 Answers 4

4

"/\+?) -- that ) is unmatched. You either need to place an opening paren somewhere in front of it or get rid of it. Not sure which would be best for whatever it is you're trying to do.

1
  • What I am trying to do, is to get som data extracted from the following: [quote=quote-userName (32)]quote text[/quote]... I would like to get the current data: "quote-userName (32)" and "quote text" extracted!
    – fischer
    Jan 26, 2011 at 12:07
2

It's telling you that the first ), which occurs as the third character in the expression after the escaped + and the question mark, is unmatched. Either there's a missing ( at the start of the expression or this ) should be escaped to \).

2

Try removing the first closing parenthesis:

\+?\)(=.+?,.+?)?\](.+?)\[\/quote\](?!((.*?)\[\/quote\]))

Or escape it, like this:

\+?\)\)(=.+?,.+?)?\](.+?)\[\/quote\](?!((.*?)\[\/quote\]))
1

Missing backslash

   123
"/\+?)\)(=.+?,.+?)?\](.+?)\[\/quote\](?!((.*?)\[\/quote\]))/s"
     ^ --- here
"/\+?\)\)(=.+?,.+?)?\](.+?)\[\/quote\](?!((.*?)\[\/quote\]))/s"

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.