import rea="abc abc abc efg 123 abc 123 abc abc xyz 123"b=re.findall(r"\babc\b(?! abc\b).*?\b123\b",a)print (b)
Standard input is empty
['abc efg 123', 'abc 123', 'abc xyz 123']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!