我正在尝试确定字符串是否与正则表达式模式匹配:
expected = re.compile(r'session \d+: running')
string = "session 1234567890: running"
re.match(expected, string)
但是,re.match()
总是返回None
。我是否试图错误地匹配小数?这个数字应该是 10 位数字,但我想涵盖它或多或少数字的情况。
编辑:字符串参数实际上是先前匹配的结果:
expected = re.compile(r'session \d+: running')
found = re.match(otherRegex, otherString)
re.match(expected, found.groups()[0])
当我打印found.groups()[0]
它打印的类型class str
时,当我打印时found.groups()[0]
,它打印我期望的字符串:"session 1234567890: running"
。这可能是它对我不起作用的原因吗?