[英]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.