Перебирать строки в списке phrase
:
import re
def multi_re_find(patterns,phrase):
for phrase_s in phrase: # phrase_s is a string
for pat in patterns:
print("Searching for pattern '{}' in '{}'".format(pat, phrase_s))
print(re.findall(pat,phrase_s))
print("\n")
test_phrase1 = ["This is a string! But it has punctuation. How can we remove it?"]
test_pattern1 = ['[^!.? ]+']
multi_re_find(test_pattern1,test_phrase1)
Python demo
Вывод:
Searching for pattern '[^!.? ]+' in 'This is a string! But it has punctuation. How can we remove it?'
['This', 'is', 'a', 'string', 'But', 'it', 'has', 'punctuation', 'How', 'can', 'we', 'remove', 'it']