Regex for checking if a string has mismatched parentheses?

后端 未结 8 2143
一生所求
一生所求 2020-11-29 05:41

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)
8条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 06:05

    Agree with the fact that this is impossible with a REGEX. You could do the following, though:

    
    

提交回复
热议问题