0

Say I have a word that I'm trying to match from a .txt file

word = "hello"

How do I add word boundaries (\b) on both ends so I can just match the exact word. So without the variable it'll look like this:

x = re.search(r'\bhello\b', txt)

but since I'm taking the string as an input, I want it to add the boundaries to my variable instead.

0 Answers0