Python 简单的正则表达式

标签 python regex

所以我有一个模式:

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/

相关文章:

python - 如何批量删除桶

python - 如何使用 xpath 和 Robotframework 在 div 中定位标签名称

python - POS-Tagger 非常慢

python - 需要了解如何使用环视来提取非重叠序列

php - 没有 http|https 的外部链接失败

python - 多个过滤器 Python Data.frame

regex - 使用 AND 使用 Sublime 3 在多个文件中搜索多个字符串

regex - 如何限制某个字符前的匹配长度?

JavaScript:字符串匹配后返回 anchor 标记

javascript - 正则表达式匹配 HTML 正文的内容