My code looks like this.
for userinput in sys.argv[1:]:
pattern = re.compile(userinput, flags = re.IGNORECASE)
if re.search(pattern, string):
do action
I want to search through a string of text using this pattern but exclude the cases where the pattern exists in between a different word, such as 'hi' inside 'which'. So I tried putting the word boundary
pattern = re.compile('\buserinput\b', flags = re.IGNORECASE)
but I realized this will search the literal string 'userinput'. How do I add word boundaries to the patterns that change over the loop?