I've run into a regex problem I don't understand. I'm trying to replace a comma in between strings with a semi-colon and it's not working. Here's a sample string below. I set up a regex to replace everything but the content after "sequence" in a regex non-capture group, so that the comma on the end should be replaced with the only substring in the non-capture group, the semi-colon. But, it doesn't work. It only seems to preserve any of the string when I put (?:sequence:) as the non-capture groups. As soon as I add \d, it replaces the entire thing. I'm not sure why.
In my real problem, I have a serious of content tags marked with a colon and end with a semi-colon. In the tag sequence, there's a mistaken comma instead of semi-colon which I need to replace but leave everything unchanged. So, the solution should just change sequence:2, to sequence:2;
a_string = "tag1: content1 is this tag2: 0.1 amount; tag3: july 2020; sequence:2, tag4: content4"
new_string = re.sub(r"(?:sequence\:)(?:\d)(\,)", ";", a_string)
new_string
I looked at other solutions that should work, but don't for this. Any help is appreciated and please let me know if I can make this question any more clear.