[英]Regular expression in python that check if the string just contains letters, numbers and dot(.)
[英]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.