I'm using regex to find a car plate inside of a given input from a user,
numberPlate = input("Enter the Number plate of the car, eg LV04 HNX, HR06PRK")
numberPlateRegEx = re.compile(r'\w\w\d\d( )?\w\w\w') # Creates a regular expression object, can be used to scan strings for anything matching the given pattern, \w is a letter, \d is (strictly, a number or letter), ( )? means there can be an optional space
numberPlateFound = re.findall(numberPlateRegEx, numberPlate)
When I enter an input including a pattern including a car number plate then numberPlateFound is a list with a single space inside of it:
And when I enter an input not including a car number plate inside:
This works if i want to just find if something was found, but what If i want to have the found pattern returned? Would I use a different method?
EDIT: My question is different from this suggested question as in my example it returns not an empty string, but a string with a space character inside, and I dont know why, I want to know why