syler
syler

Reputation: 21

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

Upvotes: 2

Views: 2008

Answers (1)

Leon
Leon

Reputation: 3036

The problem is, that re.match take 2 or 3 arguments, not 5. First the regex pattern, and the string to match. 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. If you want multiple letters or digits, you can use [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]+.

Edit: After reading your comment, the regex you want is [0-9]{2}[a-zA-Z]{2}

Upvotes: 3

Related Questions