[英]TypeError: match() takes from 2 to 3 positional arguments but 5 were given
Full Error: 完全错误:
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
My code: 我的代码:
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!")
I'm trying to search a string with a given parameter 我正在尝试搜索具有给定参数的字符串
The problem is, that re.match
take 2 or 3 arguments, not 5. First the regex pattern, and the string to match. 问题是, re.match
需要2或3个参数,而不是5个参数。首先是正则表达式模式,然后是要匹配的字符串。 optionally it takes a 3rd argument with flags. 可选地,它需要带有标志的第三个参数。 If you want to match a single digit or a letter, you would use [0-9a-zA-Z]
as regex. 如果要匹配一个数字或字母,则可以使用[0-9a-zA-Z]
作为正则表达式。 If you want multiple letters or digits, you can use [0-9a-zA-Z]+
. 如果需要多个字母或数字,可以使用[0-9a-zA-Z]+
。 If you want a list of digits or a list of letters (but not mixed), you can use ([0-9]+)|[a-zA-Z]+
. 如果您想要一个数字列表或一个字母列表(但不混合),则可以使用([0-9]+)|[a-zA-Z]+
。
Edit: After reading your comment, the regex you want is [0-9]{2}[a-zA-Z]{2}
编辑:阅读评论后,所需的正则表达式为[0-9]{2}[a-zA-Z]{2}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.