Regular expressions: replace comma in string, Python

Viewed 2906

Somehow puzzled by the way regular expressions work in python, I am looking to replace all commas inside strings that are preceded by a letter and followed either by a letter or a whitespace. For example:

2015,1674,240/09,PEOPLE V. MICHAEL JORDAN,15,15
2015,2135,602832/09,DOYLE V ICON, LLC,15,15

The first line has effectively 6 columns, while the second line has 7 columns. Thus I am trying to replace the comma between (N, L) in the second line by a whitespace (N L) as so:

2015,2135,602832/09,DOYLE V ICON LLC,15,15

This is what I have tried so far, without success however:

new_text = re.sub(r'([\w],[\s\w|\w])', "", text) 

Any ideas where I am wrong?

Help would be much appreciated!

2 Answers
Related