Check if text has at least 2 groups of alphanumeric char (including letters, numbers, and underscores) separated by one or more whitespace characters

Viewed 12

I am not getting how the expression "\w\s+\w" satisfies the conditions of the Qn. Code is as below :

import re
def check_character_groups(text):
    result = re.search(r"\w\s+\w", text)
    return result != None

print(check_character_groups("One")) # False
print(check_character_groups("123  Ready Set GO")) # True
print(check_character_groups("username user_01")) # True
print(check_character_groups("shopping_list: milk, bread, eggs.")) # False
0 Answers
Related