Apr-24-2017, 03:43 PM
Using the csv module is probably the way to go, since it'll handle the quotes for you. But as usual, a regular expression also works:
>>> text = ''' ... Id,Category,Description,Date ... 1,Test,Red Cars,02/12/2017 ... 2,Test,Blue Cars,03/01/2017 ... 3,Test,"Green, big cars",01/05/2016 ... ''' >>> import re >>> regex = re.compile(r'("[^",]*),([^",]*")') >>> print(regex.sub(r'\1^\2', text)) Id,Category,Description,Date 1,Test,Red Cars,02/12/2017 2,Test,Blue Cars,03/01/2017 3,Test,"Green^ big cars",01/05/2016