我试图用正则表达式传递变量(检索)但我似乎无法使用下面的代码成功地将信息读入match.group(1)
、(2)
等。有人能看一下我哪里出错了吗?你知道吗
serial = 'abcdeID:11111abcdePR:22222abcde'
id = 11111
pr = 22222
match = re.search(r'ID:{0}PR:{1}'.format(id, pr), serial)
print("ID value returned = " + match.group(1))
print("PR value returned = " + match.group(2))
#output
#AttributeError: 'NoneType' object has no attribute 'group'
正则表达式中没有组
(...)
,因此不会返回它们。像这样添加:相关问题 更多 >
编程相关推荐