I am looking for a regex expression in Python. I have a long line of text and I have a list of substrings to match in a long line of text.
Examples of substrings in: 'table', 'e furnish' Example string:
'Today is a good day to do up the table furnishings. Lets go to the store.'
For the βtableβ I would like to extract the βtableβ. For "e furnish" I would like to extract the "dining room furniture".
My current code is:
for item in checklist:
pattern = r"[\s](.*)" + item +"([a-z]){0,2}[\s\.]"
print pattern
matchObj = re.search(pattern, line)
if matchObj:
print "matchObj.group() : ", matchObj.group()
else:
print ("No match!!")
but i can't take whole words encapsulating substrings. The fact is that substrings can be one or several words, and this can correspond to whole words or just part of words. For these substrings with several words, the extracted words should be together without another word between them.
Thanks for the help, everyone.