You need to escape your backslash:
p.sub('gray \\1', s)
alternatively you can use a raw string as you already did for the regex:
p.sub(r'gray \1', s)
You need to escape your backslash:
p.sub('gray \\1', s)
alternatively you can use a raw string as you already did for the regex:
p.sub(r'gray \1', s)