So lets say I have the following strings:
stringX = ['187-49481,14',
'181-457216',
'196,61-04-22',
'1972-10-28',
'19,940-04-16',
'2017-08,8-29',
'2014-04-18']
Notice that I have two types of strings: the type 181-457216 and the type 1972-10-28 (date) I'm modifying a CSV, and for some reason (looked it up hard, didn't find any reason), it sometimes -apparently randomly- inserts a comma between numbers in these types of strings.
So what I want to accomplish is to just detect these commas through regular expression and replace them by empty (remove the commas).
Say for the first type of string, i.e: '187-14,412' I've been trying:
re.sub(r'\d+\-\d+(\,)\d+', '', stringX)
In this example, the comma is group 1, but how can I specify to sub group(1) in this regex ?
I've also been trying lookbehind and lookahead, but have trouble with the lookbehind:
(?<=\d+\-\d+)(\,)(?=\d+)
Err: lookbehind assertion is not fixed length at offset 0
I was wandering if there is a better way to regex these strings, or to be able to specify group(1) on the re.sub