树字符串操作的正则表达式

时间:2015-03-15 04:56:51

标签: python regex string expression

我有以下字符串:

(S{4077..4157} (IN{4077..4081} '(,{4157..4158} ,{4157..4158}) (S{4159..4288} (IN{4159..4163} that{4159..4163})'

我想提取S{4077..4157},{4157..4158}) (S{4159..4288}模式:

我试过这个正则表达式:

match = re.compile( r',([{[0-9]+..[0-9}]+[)])*[\s]*[(SBAR{][{0-9]+..[0-9}]', re.M|re.I)

for tr in trees:
    #tr.draw()
    tr1=str(tr)

    matchObj =  match.findall(s)
    if matchObj:
        print ("match : ", matchObj)
    else:
        print ("No match!!") 

1 个答案:

答案 0 :(得分:0)

match = re.compile( r'\((S\{\d+..\d+})\s+\(\w+\{\d+..\d+\}\s+'\((,\{\d+..\d+\})\s+,\{\d+..\d+\}\)\s*\((S\{\d+..\d+\})', re.M|re.I)

for tr in trees:
    #tr.draw()
    tr1=str(tr)

    matchObj =  match.findall(s)
    if matchObj:
        print math.group(1)
        print match.group(2)
        print match.group(3)
    else:
        print ("No match!!")