fork download
  1. import re
  2. a="abc abc abc efg 123 abc 123 abc abc xyz 123"
  3. b=re.findall(r"\babc\b(?! abc\b).*?\b123\b",a)
  4. print (b)
Success #stdin #stdout 0.02s 9400KB
stdin
Standard input is empty
stdout
['abc efg 123', 'abc 123', 'abc xyz 123']