Am trying to match a name in the pattern "FirstnameSpaceLastname" e.g John Doe, just the first and last name with a space in between, how can I go about it? the code is below shows what i.ve tried:
user_input = input("Enter you full names: ")
def valid_name():
#name_regex = re.compile('^[a-zA-Z\\sa-zA-Z]$')
#name_regex = re.compile('^[a-zA-Z]\s[a-zA-Z]$')
#name_regex = re.compile('^[a-zA-Z a-zA-Z]+$')
#name_regex = re.compile('^a-zA-Z\sa-zA-Z$')
name_regex = re.compile('^[a-zA-Z a-zA-Z]$')
nameMatch = re.match(name_regex, user_input)
if nameMatch:
print(user_input)
else:
print('Enter name in (Firstname Lastname) format')
valid_name()
[a-zA-Z a-zA-Z]is the same as[a-zA-Z ](Note that names can have a great variety in length and characters)r"(\w+)\s+(\w+)"work for you?