我想返回一个列表,其中包含句子中存在的所有匹配的范围和值,但我不知道确切的python语法。
import re
sens = 'SCOTT GORRAN 08:09:17 thx 08:19:33 where do you have eur m17->m27? 6s. imm rolls. KATHERINE DOUGLAS 08:19:47 sec BARRY CLARK 08:20:16 84 SCOTT GORRAN 08:21:25 offer usd 25k/bp pls'
pattern = r'([\+-]?((\d+(\,\d{3})+)(\.\d+)?)|\d+(\.\d+)?|(\.\d+))'
compiled = re.compile(pattern, re.IGNORECASE)
list_of_matches =[]
for match in compiled.match(sens):
match_tuple = (match.span(), match.value())
list_of_matches.append(match_tuple)
输出应该是这样的:
[((start,end),value) ... ]
[((13,15),08) , ((16,18),09), ((26,28), 08), ((29,31), 19) ....]
任何人都知道如何做到这一点?
由于