What is \1 here?

satishmlmlml at gmail.com satishmlmlml at gmail.com
Tue Nov 11 10:18:02 CET 2014

What does \1 do in the following piece of code(fourth line)?
import re
print(re.sub('[ABC]', '*', 'XAXAXBXBXCXC'))
print(re.sub('[ABC]_', '*', 'XA-XA_XB-XB_XC-XC_'))
print(re.sub('(.) spam', 'spam\\1', 'x spam, y spam'))
def mapper(matchobj):
       return 'spam' + matchobj.group(1)
print(re.sub('(.) spam', mapper, 'x spam, y spam'))

More information about the Python-list mailing list