簡體   English   中英

Python中的正則表達式無法解析包含點的字符串

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM