Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80523
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'patterns.': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'wrote': 0.14; "wouldn't": 0.14; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'import': 0.22; 'print': 0.22; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'see,': 0.30; "skip:' 10": 0.31; 'piece': 0.31; 'spam,': 0.31; 'guess': 0.33; 'raw': 0.33; "i'd": 0.34; "i'll": 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'that,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'email addr:gmail.com': 0.63; 'subject:here': 0.84; 'subject::': 0.85 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dave Angel <davea@davea.name> |
| Subject | Re:What is \1 here? |
| Date | Tue, 11 Nov 2014 07:22:44 -0500 (EST) |
| Organization | news.gmane.org |
| References | <6720bebb-8263-4fb1-bcef-10dcfdc44905@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | 97.73.240.77 |
| X-Newsreader | PiaoHong.Usenet.Client.VIP:1.64 |
| X-Archive | encrypt |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15661.1415708571.18130.python-list@python.org> (permalink) |
| Lines | 24 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1415708571 news.xs4all.nl 2874 [2001:888:2000:d::a6]:53923 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:80523 |
Show key headers only | View raw
satishmlmlml@gmail.com Wrote in message:
> 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'))
>
>
Recommend you use raw strings when defining regex patterns. Then
you wouldn't have to double the backslash.
To see what re.sub will see, try
print ('spam\\1')
As for what the function does with that, I'll have to guess, as I
don't do regex. I'd guess it'll match any digit.
--
DaveA
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