strs = '1(2(3(4(5(67)6)7)8)9)0'
reg1 = re.compile('\(([^()])*\)') #一对括号
reg2 = re.compile('\(([^()]|\([^()]*\))*\)') #两对括号
reg3 = re.compile('\(([^()]|\([^()]*\)|\(([^()]|\([^()]*\))*\))*\)') #三层
函数
#匹配成对括号正则表达式
def getReg(self, count, bracket = '()'):
leftBracket = bracket[0]
rightBracket = bracket[1]
count -= 1
regBasic = leftBracket + '(?:[^' + leftBracket + rightBracket + '])*' + rightBracket
if count < 0:
regBasic = ''
if count > 0:
for i in xrange(count):
tempNum = regBasic.rfind('*') - 1
regBasic = regBasic[:tempNum] + "|" + regBasic + regBasic[tempNum:]
return regBasic