我对Python正则表达式有疑问。
>>> import re
>>> print re.match('img', 'test.img')
None
>>> print re.match('test', 'test.img')
<_sre.SRE_Match object at 0x7f3fac8a0100>
>>>
dot(。)之后的任何字符都不会被解析,有什么办法可以解决这个问题?
re.match
仅在字符串的开头匹配。使用search
代替。(请参阅search()
vs。match()
)
>>> import re
>>> re.match('img', 'test.img')
>>> re.search('img', 'test.img')
<_sre.SRE_Match object at 0x0000000002AB0100>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句