import rep = re.compile(r',?\+\d+_[^,]+')test_str = "+1223,+12_remove_me,+222,+2223_remove_me"result = p.sub("", test_str)print(result)
Standard input is empty
+1223,+222
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!