2

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?

jon
  • 35
  • 9

1 Answers1

2

You haven't any word boundary after the dot, just remove it from the pattern:

re.search(r"\b[A-Z]\.", 'A.')
Toto
  • 89,455
  • 62
  • 89
  • 125