PCRE (recursive) pattern that matches a string containing a correctly parenthesized substring. Why d
Posted
by Anton N. Petrov
on Stack Overflow
See other posts from Stack Overflow
or by Anton N. Petrov
Published on 2010-06-04T11:26:16Z
Indexed on
2010/06/05
23:12 UTC
Read the original article
Hit count: 201
Well, there are other ways (hmmm... or rather working ways) to do it, but the question is why does this one fail?
/
\A # start of the string
( # group 1
(?: # group 2
[^()]* # something other than parentheses (greedy)
| # or
\( (?1) \) # parenthesized group 1
) # -group 2
+ # at least once (greedy)
) # -group 1
\Z # end of the string
/x
Fails to match a string with nested parentheses: "(())"
© Stack Overflow or respective owner