I am trying to extract words from item_search list. My regular expression works for normal words. However, it does not work for the words that contain unbalanced parenthesis. Here is the code:
import re
strn = """
Hello every@one, I am trying@this code/module-but not work(ing properly)for
unknown reason(s). It always stop with @regula-expression_error12
"""
item_search = ["Hello", "every@one","trying@this", "code/module-but", "work(ing properly)", "reason(s)", "@regula-expression_error12)" ]
item=list(set(re.findall(rf"(?<!\S)({'|'.join(item_search)})\W*(?!\S)", strn, flags=re.MULTILINE | re.UNICODE)))
item
error:
error: unbalanced parenthesis at position 108
Looking for experts suggestions.