fork(1) 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"(?<!\w)[{0}]+(?!\w)".format(re.escape(kw)))
  5. print(r.findall(s))
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
['a', '^submarine', 'be', '^marines', 'as', 'a']