简体   繁体   English

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

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

I got a problem about Python Regex. 我对Python正则表达式有疑问。

>>> import re
>>> print re.match('img', 'test.img')
None
>>> print re.match('test', 'test.img')
<_sre.SRE_Match object at 0x7f3fac8a0100>
>>>

Any character after dot(.) won't be parsed, is there any way to solve this problem? dot(。)之后的任何字符都不会被解析,有什么办法解决这个问题?

re.match matches only at the beginning of the string. re.match仅在字符串的开头匹配。 Use search instead. 请改用search (See search() vs. match() ) (请参阅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