In a PHP script, what regex should I use to check for mismatched parentheses in a string? Things that I want to allow include:
- This is (ok)
- This (is) (ok)
Things I want to prevent:
- This is )bad(
- This is also (bad
- This is (bad (too)
Update: You guys all rock. Doing this with a regex seemed trickier than it should have, and these kinds of 2nd level answers are what makes beautiful. Thanks for the links and the pseudocode. I'm not sure who to give the answer to, so I apologize to everyone whose answers I can't accept.
Regex is not the right tool for the job. Scan a string manually.