gpt4 book ai didi

Python 简单的正则表达式

转载 作者:太空宇宙 更新时间:2023-11-03 12:50:55 25 4
gpt4 key购买 nike

所以我有一个模式:

hourPattern = re.compile('\d{2}:\d{2}')

并匹配编译后的模式

hourStart = hourPattern.match('Sat Jan 28 01:15:00 GMT 2012') 

当我打印 hourStart 时,它没有给我任何信息。有帮助吗?

最佳答案

匹配期望找到的值位于字符串的开头。你想要搜索。

>>> import re
>>>
>>> s = re.compile('\d+')
>>>
>>> s2 = 'a123'
>>>
>>> s.match(s2)
>>> s.search(s2)
<_sre.SRE_Match object at 0x01E29AD8>

关于Python 简单的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8129648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com