gpt4 book ai didi

python - 类型错误 : match() takes from 2 to 3 positional arguments but 5 were given

转载 作者:行者123 更新时间:2023-12-01 03:39:53 24 4
gpt4 key购买 nike

完全错误:

Traceback (most recent call last):
File "N:/Computing (Programming)/Code/name.py", line 3, in <module>
valid = re.match("[0-9]","[0-9]","[A-Z]","[a-z]" ,tutorGroup)
TypeError: match() takes from 2 to 3 positional arguments but 5 were given

我的代码:

import re
tutorGroup = input("Enter your tutor group - e.g. 10: ")
valid = re.match("[0-9]","[0-9]","[A-Z]","[a-z]" ,tutorGroup)
if valid:
print("OK!")
else:
print("Invalid!")

我正在尝试使用给定参数搜索字符串

最佳答案

问题是,re.match 采用 2 或 3 个参数,而不是 5 个。首先是正则表达式模式,然后是要匹配的字符串。可选地,它需要带有标志的第三个参数。如果您想匹配单个数字或字母,您可以使用 [0-9a-zA-Z] 作为正则表达式。如果您想要多个字母或数字,可以使用[0-9a-zA-Z]+。如果您想要数字列表或字母列表(但不是混合),可以使用 ([0-9]+)|[a-zA-Z]+

编辑:阅读您的评论后,您想要的正则表达式是 [0-9]{2}[a-zA-Z]{2}

关于python - 类型错误 : match() takes from 2 to 3 positional arguments but 5 were given,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39767891/

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