简体   繁体   English

TypeError:match()接受2到3个位置参数,但给出了5个

[英]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.

相关问题 类型错误:raw_input() 需要 1 到 2 个位置参数,但给出了 4 个 - TypeError: raw_input() takes from 1 to 2 positional arguments but 4 were given Django TypeError:url()需要2到4个位置参数,但是给出了16个 - Django TypeError: url() takes from 2 to 4 positional arguments but 16 were given 继承 TypeError: __init__() 接受 1 到 2 个位置参数,但给出了 8 个 - inheritance TypeError: __init__() takes from 1 to 2 positional arguments but 8 were given TypeError: append() 从 2 到 5 个位置 arguments 但给出了 8 个 - TypeError: append() takes from 2 to 5 positional arguments but 8 were given TypeError: with_column() 从 3 到 4 个位置 arguments 但给出了 5 个(python) - TypeError: with_column() takes from 3 to 4 positional arguments but 5 were given (python) Tkinter | TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given - Tkinter | TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given Python: TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given - Python : TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given Money 和 TypeError:__init__() 需要 1 到 2 个位置参数,但给出了 3 个 - Money and TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given 类型错误:execute() 需要 2 到 3 个位置参数,但给出了 7 个 - TypeError: execute() takes from 2 to 3 positional arguments but 7 were given TypeError:send()接受1到2个位置参数,但给出了3个 - TypeError: send() takes from 1 to 2 positional arguments but 3 were given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM