fork download
  1. import re
  2. s = "I have a string submarine I want to be able to detect marines as a match"
  3. kw = "submarine"
  4. r = re.compile(r"\b[{0}]+\b".format(kw))
  5. print(r.findall(s))
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
['a', 'submarine', 'be', 'marines', 'as', 'a']