How to make \b properly respect the word boundary? For example, understand the ' and not does partial match...
>>> import re
>>> str = "This is a test's test"
>>> p1 = r'\b' + 'test' + r'\b'
Using negative look-ahead assertion, you can assure matching
test that is not followed by
>>> import re >>> s = "This is a test's test" >>> re.findall(r"\btest\b(?!')", s) # match `test` as long as it is not followed by "'" ['test']
BTW, do not use
str as a variable name. It shadows built-in function/type