I'm attempting to modify strings using the .sub() function from the re module. More specifically, I'm trying to use a group backref but the function doesn't seem to register the function. For example:
> In [49]: s = ' STORE # 123 123 '
> In [50]: print re.sub('([0-9]+) +(\1)','(\1)',s)
STORE # 123 123
I want it to print "STORE # 123" but it seems like the first arg of .sub() isn't registering so it just spits out the initial string unmodified. I've even checked the documentation (https://docs.python.org/2/library/re.html#re.sub) and still can't figure out what I'm doing wrong. I'm running Python 2.7 by the way.
Thanks for the help!