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