import re
def multi_re_find( patterns, phrase) :
for phrase_s in phrase:
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)
aW1wb3J0IHJlCgpkZWYgbXVsdGlfcmVfZmluZChwYXR0ZXJucyxwaHJhc2UpOgogICAgZm9yIHBocmFzZV9zIGluIHBocmFzZToKICAgICAgICBmb3IgcGF0IGluIHBhdHRlcm5zOgogICAgICAgICAgICBwcmludCgiU2VhcmNoaW5nIGZvciBwYXR0ZXJuICd7fScgaW4gJ3t9JyIuZm9ybWF0KHBhdCwgcGhyYXNlX3MpKQogICAgICAgICAgICBwcmludChyZS5maW5kYWxsKHBhdCxwaHJhc2VfcykpCiAgICAgICAgICAgIHByaW50KCJcbiIpCgp0ZXN0X3BocmFzZTEgPSBbIlRoaXMgaXMgYSBzdHJpbmchIEJ1dCBpdCBoYXMgcHVuY3R1YXRpb24uIEhvdyBjYW4gd2UgcmVtb3ZlIGl0PyJdCnRlc3RfcGF0dGVybjEgPSBbJ1teIS4/IF0rJ10KCm11bHRpX3JlX2ZpbmQodGVzdF9wYXR0ZXJuMSx0ZXN0X3BocmFzZTEp
stdout
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']