fork download
  1. import re
  2. print( re.sub(r'("[^"]*")|,',
  3. lambda x: x.group(1) if x.group(1) else x.group().replace(",", ""),
  4. '1,2,"test,3,7","4, 5,6, ... "') )
  5. # => 12"test,3,7""4, 5,6, ... "
  6.  
  7. print( re.sub(r'(?s)("[^"\\]*(?:\\.[^"\\]*)*")|,',
  8. lambda x: x.group(1) if x.group(1) else x.group().replace(",", ""),
  9. r'1,2,"test, \"a,b,c\" ,03","4, 5,6, ... "') )
  10. # => 12"test, \"a,b,c\" ,03""4, 5,6, ... "
Success #stdin #stdout 0.02s 9512KB
stdin
Standard input is empty
stdout
12"test,3,7""4, 5,6, ... "
12"test, \"a,b,c\" ,03""4, 5,6, ... "