import restrings = ['foo, bar 12,6','foo, bar 12, 6','foo, bar 12 ,6','foo, bar 12,','foo, bar ,6','foo,5','foo ,5']for s in strings: print(s, '=>', re.sub(r'(\d\s*,)(?=\s*\d)|,', r'\1', s))
Standard input is empty
foo, bar 12,6 => foo bar 12,6 foo, bar 12, 6 => foo bar 12, 6 foo, bar 12 ,6 => foo bar 12 ,6 foo, bar 12, => foo bar 12 foo, bar ,6 => foo bar 6 foo,5 => foo5 foo ,5 => foo 5
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!