写了这么多年 python 了,今天遇到一个不太明白的问题。
问题就如标题(为了简短期间,标题里面稍作改动)。
这样死活匹配不出来:
>>> r = re.match(': (?P<timeout>\d+) ms', 'Screen off timeout: 10000 ms')
>>> r
>>> print(r)
None
改成这样就好了:
>>> r = re.match('Screen off timeout: (?P<timeout>\d+) ms', 'Screen off timeout: 10000 ms')
>>> r
<_sre.SRE_Match object; span=(0, 28), match='Screen off timeout: 10000 ms'>
求大虾指点其原理?在线跪等