import res = '(X_xy09 and X_foobar or (X_abc123 and X_something))'print(re.sub(r'\b[A-Z]_([a-zA-Z0-9])', r'\1', s))
Standard input is empty
(xy09 and foobar or (abc123 and something))
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!