fork download
  1. import re
  2. strs = ['I have to go out with Jane','I have to go out to the movies with Jane']
  3. rx = re.compile(r'(?si)\b(\w+)\b(?=.*?\b\1\b)')
  4. for s in strs:
  5. print(s, "=>", rx.findall(s))
Success #stdin #stdout 0.02s 9644KB
stdin
Standard input is empty
stdout
I have to go out with Jane => []
I have to go out to the movies with Jane => ['to']