Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80521
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Subject | Re: What is \1 here? |
| Date | 2014-11-11 06:52 -0500 |
| References | <6720bebb-8263-4fb1-bcef-10dcfdc44905@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15659.1415706751.18130.python-list@python.org> (permalink) |
On 11/11/14 4:18 AM, satishmlmlml@gmail.com wrote:
> 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'))
>
Maybe you can't tell from the reception you're getting here: People are
growing tired of your questions about basic Python behavior. They want
you to find a way to learn for yourself. You're asking about regular
expressions. The Python docs have an extensive page detailing how they
work: https://docs.python.org/3/library/re.html
You need to learn how to find this stuff out for yourself. Ben Finney
even gave you a pointer to a helpful site for experimenting with
regexes: http://pythex.org/
--
Ned Batchelder, http://nedbatchelder.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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