Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80515

What is \1 here?

Newsgroups comp.lang.python
Date 2014-11-11 01:18 -0800
Message-ID <6720bebb-8263-4fb1-bcef-10dcfdc44905@googlegroups.com> (permalink)
Subject What is \1 here?
From satishmlmlml@gmail.com

Show all headers | View raw


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'))

Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

What is \1 here? satishmlmlml@gmail.com - 2014-11-11 01:18 -0800
  Re: What is \1 here? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-11 10:03 +0000
  Re: What is \1 here? Ned Batchelder <ned@nedbatchelder.com> - 2014-11-11 06:52 -0500
  Re:What is \1 here? Dave Angel <davea@davea.name> - 2014-11-11 07:22 -0500
  Re: What is \1 here? Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-11 17:35 +0000

csiph-web