【问题标题】:regular expression for tree string manipulation用于树字符串操作的正则表达式
【发布时间】:2015-03-15 04:56:51
【问题描述】:

我有以下字符串:

(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!!") 

【问题讨论】:

  • ...当你尝试它时发生了什么?
  • 有什么逻辑吗?为什么你只想提取这三个?

标签: python regex string expression


【解决方案1】:
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!!") 

【讨论】:

    猜你喜欢
    • 2013-04-01
    • 2011-04-06
    • 2017-03-08
    • 1970-01-01
    • 2011-12-20
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    相关资源
    最近更新 更多