例如,鉴于这一段
.This是图3a。这是图4a。我喜欢(图5)。这是重要的(图6a)。
我希望用python来提取基于数字的句子。我在努力
但匹配并不具体。例如,数字4将提取所有数字。我只是基于数字的一个具体数字
发布于 2015-10-10 03:46:42
你需要替换,
.*先于4和[^.]*4替换为\d代码:
In[3]: s = "This is figure 3a. This is fig 4a . I like (figure 5). This is important (fig 6a)."
In[4]: import re
In[5]: re.findall(r'[^.]*?fig[^.]*\d[^.]*', s)
Out[5]:
['This is figure 3a',
' This is fig 4a ',
' I like (figure 5)',
' This is important (fig 6a)']或
In[8]: re.findall(r'\s*([^.]*?fig[^.]*\d[^.]*?)(?=\s*\.)', s)
Out[8]:
['This is figure 3a',
'This is fig 4a',
'I like (figure 5)',
'This is important (fig 6a)']https://stackoverflow.com/questions/33049967
复制相似问题