import rerx = r"X.*?C.*?(B|Y|A)"s = "X Hello C there. I am B a String. Y I C am a A good string."print(re.sub(rx, r"\1", s))
Standard input is empty
B a String. Y I C am a A good string.
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!