Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.12; 'detailing': 0.16; 'expressions.': 0.16; 'finney': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'url:re': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User- Agent:1': 0.23; 'pointer': 0.24; 'received:comcast.net': 0.24; 'helpful': 0.24; 'asking': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'getting': 0.31; "skip:' 10": 0.31; 'piece': 0.31; 'spam,': 0.31; 'work:': 0.31; 'yourself.': 0.31; 'stuff': 0.32; 'regular': 0.32; 'url:python': 0.33; 'maybe': 0.34; 'basic': 0.35; "can't": 0.35; 'subject:?': 0.36; 'url:org': 0.36; 'growing': 0.38; 'ben': 0.38; 'tired': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'tell': 0.60; 'url:3': 0.61; "you're": 0.61; 'here:': 0.62; 'email addr:gmail.com': 0.63; 'subject:here': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: What is \1 here? Date: Tue, 11 Nov 2014 06:52:15 -0500 References: <6720bebb-8263-4fb1-bcef-10dcfdc44905@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <6720bebb-8263-4fb1-bcef-10dcfdc44905@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415706751 news.xs4all.nl 2948 [2001:888:2000:d::a6]:44397 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80521 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