fork download
  1. import re
  2.  
  3. def multi_re_find(patterns,phrase):
  4. for phrase_s in phrase:
  5. for pat in patterns:
  6. print("Searching for pattern '{}' in '{}'".format(pat, phrase_s))
  7. print(re.findall(pat,phrase_s))
  8. print("\n")
  9.  
  10. test_phrase1 = ["This is a string! But it has punctuation. How can we remove it?"]
  11. test_pattern1 = ['[^!.? ]+']
  12.  
  13. multi_re_find(test_pattern1,test_phrase1)
Success #stdin #stdout 0.03s 9396KB
stdin
Standard input is empty
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']