I want to test if a string contains initials such as 'A.' or 'B. M.'.
Why is
bool(re.search("\b[A-Z]\.\b", 'A.'))
returning False?
I want to test if a string contains initials such as 'A.' or 'B. M.'.
Why is
bool(re.search("\b[A-Z]\.\b", 'A.'))
returning False?
You haven't any word boundary after the dot, just remove it from the pattern:
re.search(r"\b[A-Z]\.", 'A.')