^\s*[)]*\s*$
and ^\s*[(]*\s*$
matches the parentheses (
and )
which are bold. That is, what am trying is to ignore parentheses that are single and not (condition1) parentheses:
while
( #matches here
( #matches here
(condition1) && (condition2) &&
condition3
) ||
(#matches here
(condition4) ||
condition5 &&
(condition6)
) #matches here
) #matches here
but if I have like this it does not match:
while
(( #does not match here
(condition1) && (condition2) &&
condition3
) ||
(
(condition4) ||
condition5 &&
(condition6)
) ) #does not match here
or
while
((( #does not match here
(condition1) && (condition2) &&
condition3
)) ||
(( #does not match here
(condition4) ||
condition5 && 开发者_StackOverflow
(condition6)
) ) ) #does not match here
How can I match all the parentheses that are single?
I'd personally recommend that you use a simple stack to figure out open and closing brackets rather than trip over regular expressions.
精彩评论