源字符串是:
# Python 3.4.3
s = r'abc123d, hello 3.1415926, this is my book'
这是我的模式:
pattern = r'-?[0-9]+(\\.[0-9]*)?|-?\\.[0-9]+'
然而,
re.search
可以给我正确的结果:
m = re.search(pattern, s)
print(m) # output: <_sre.SRE_Match object; span=(3, 6), match='123'>
re.findall
把一张空名单扔掉:
L = re.findall(pattern, s)
print(L) # output: ['', '', '']
为什么不能
芬德尔先生
给我期望的名单:
['123', '3.1415926']