繁体   English   中英

Python中的正则表达式无法解析包含点的字符串

[英]Regular Expression in Python can't parse string contains dot

我对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()match()

>>> import re
>>> re.match('img', 'test.img')
>>> re.search('img', 'test.img')
<_sre.SRE_Match object at 0x0000000002AB0100>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM