假设我有一个包含子串的字符串
# the substrings and the whole string surrounded by parenthesis string = '((substring1)(substring2))'
我想使用正则表达式获取substring1和substring2,但我遇到了问题:(
这就是我现在拥有的:
match = re.search('(\(.*\))', string) print match.groups()
问题是,结果显示:
('(substring1)(substring2)', )
似乎正则表达式只匹配第一个左括号和最后一个右括号.
换句话说,匹配的正则表达式就像..
( match..... )
代替
( (match1)(match2) )
如何使正则表达式捕获INNER括号?
谢谢