简体   繁体   中英

Regular Expression in Python can't parse string contains dot

I got a problem about Python Regex.

>>> 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?

re.match matches only at the beginning of the string. Use search instead. (See search() vs. match() )

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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