bigger_list_of_names = ['Jim', 'Bob', 'Fred', 'Cam', 'Reagan','Alejandro','Dee','Rana','Denisha','Nicolasa','Annett','Catrina','Louvenia','Emmanuel','Dina','Jasmine','Shirl','Jene','Leona','Lise','Dodie','Kanesha','Carmela','Yuette',]
name_list = ['Jim', 'Bob', 'Fred', 'Cam']
search_people = re.compile(r'\b({})\b'.format(r'|'.join(name_list)), re.IGNORECASE)
print(search_people)
for names in bigger_list_of_names:
found_them = search_people.search(names, re.IGNORECASE | re.X)
print(names)
if found_them:
print('I found this person: {}'.format(found_them.group()))
else:
print('Did not find them')
The issue I am having is the regex does not find the names at all and keeps hitting the else:
I have tried re.search
, re.findall
, re.find
, re.match
, re.fullmatch
, etc. They all return None
. The only way for it to find anything is if I use re.finditer
but that would not allow me to use .group()
.
The output of the re.compile
is re.compile('\\b(Jim|Bob|Fred|Cam)\\b', re.IGNORECASE)
I tested it on https://regex101.com/ () and it looks like its working but not in the python.
Am I missing anything?