I am trying to detect an exact word match in a string by iterating over a set of keywords. Therefore, I wanted to dynamically build a regex pattern that includes the keyword found in the loop. Like this:
for i, entry in sentiLexicon.iterrows():
word = entry.word
if re.match('\b' + word + '\b', text):
print(word)
I included the '\b' since I only want exact words to match, for example, the word 'stand' should not match with the word 'abstand'. I am getting the following error but it doesn't make any sense to me since I did not include a parenthesis anywhere.
re.error: unbalanced parenthesis at position 3
Does anyone have an idea on how to implement this correctly?