I know this was covered elsewhere but my use case is causing me difficulty.
What if a string has a dreaded "\3" character like this one:
new_data = r'C:\temp\3_times.csv'
...then re "thinks" that you're referring to it as a group so if you try to do a sub using that data then you get this error:
newfiledata = re.sub(old_data,new_data,filedata)
error: invalid group reference
Is there any way to avoid this error without looking for that case in the string and modifying it directly before passing it which would take lots of extra code.
Note: For the usage I'm going for modifying the string with escape characters isn't an option because I need to write the string with the sub function later on. So this is not a duplicate of the question on how to escape special characters.