import rep = re.compile(r'([a-z]) ([(a-z])')test_str = "abc def (ghi) OR jkl"subst = r"\1 AND \2"result = re.sub(p, subst, test_str)print(result)
Standard input is empty
abc AND def AND (ghi) OR jkl
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!