^\s*[)]*\s*$
和^\s*[(]*\s*$
与粗体的圆括号(
和)
相符。也就是说,我是什么想的忽略是单身,而不是(条件1)括号内括号:如何匹配Perl中的某些嵌套圆括号?
while
( #matches here
( #matches here
(condition1) && (condition2) &&
condition3
) ||
(#matches here
(condition4) ||
condition5 &&
(condition6)
) #matches here
) #matches here
但如果我有这样的不匹配:
while
((#does not match here
(condition1) && (condition2) &&
condition3
) ||
(
(condition4) ||
condition5 &&
(condition6)
)) #does not match here
或
while
(((#does not match here
(condition1) && (condition2) &&
condition3
)) ||
(( #does not match here
(condition4) ||
condition5 &&
(condition6)
))) #does not match here
如何匹配所有单个括号?
请给我们一些数据! – 2010-01-25 11:41:57
所以基本上你想匹配所有的括号,除了最内层的那个,我说得对吗? – Amarghosh 2010-01-25 11:43:00
你应该真的使用解析器。正则表达式不能用于表达非常规语言,如你的。 – Gumbo 2010-01-25 11:44:13