我想获得的位置<,并>认为是真实的tag,当它们被嵌入在这样的事情<tag "510270">calculate</>。
我有这样的句子:
sentence = "After six weeks and seventeen tentative approaches the only serious
tender came from Daniel. He had offered a paltry #2 a week for the one-time
woodman's home, sane enough in this, at least, to <tag "510270">calculate</>
safety to the nearest new penny piece. "
sentence2 = "After six weeks and seventeen tentative approaches the only serious
tender came from Daniel. He had offered a paltry #2 a week for the one-time
woodman's < home, sane enough in this, at least, to <tag "510270">calculate</>
safety to the nearest new penny > piece. "
sentence3 = "After six weeks and seventeen tentative approaches the only serious
tender came from Daniel. He had offered a paltry #2 a week for the one-time
woodman's > home, sane enough in this, at least, to <tag "510270">calculate</>
safety to the nearest new penny < piece. "
我需要的cfrom和incfrom是和第一的位置第2<内的<tag "XXXX">...</>,我需要的CTO和incto是第1第2的位置和>内<tag "XXXX">...</>
对于句子2和句子3之类的句子,该句子在哪里出现<或>出现在哪里,我该<tag "XXXX">...</>怎么办?
对于句子1,我可以简单地做到这一点:
cfrom,cto = 0,0
for i,c in enumerate(sentence1):
if c == "<":
cfrom == i
break
for i,c in enumerate(sentence1.reverse):
if c == ">":
cto == len(sentence)-i
break
incfrom incto = 0,0
fromtrigger, totrigger = False, False
for i,c in enumerate(sentence1[cfrom:]):
if c == ">":
incfrom = cfrom+i
break
for i,c in enumerate(sentence1[incfrom:cto]):
if c == "<":
incto = i
break
鸿蒙传说
相关分类