【发布时间】:2020-08-12 07:52:35
【问题描述】:
我对 re.findall 有疑问
例如。
text = '[1]xxxxxxxx[2]xxxxxxxx[3]xxxxxx[4]xxxxxxxxxend'
re.findall('(\[\d{1,2}\].*?)(?:\[\d{1,2}\]|end)',text)
我想要的是提取["[1]xxxxxxxx","[2]xxxxxxxx","[3]xxxxxx","[4]xxxxxxxxx"]。
但是当我做了re.findall('(\[\d{1,2}\].*?)(?:\[\d{1,2}\]|end)',text)
我收到了['[1]xxxxxxxx', '[3]xxxxxx']
这个问题祝你好运
【问题讨论】:
-
在非捕获组中使用前瞻,参见regex101.com/r/I6HSyG/1