Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.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.061 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; '"("': 0.09; 'append': 0.09; 'friday,': 0.09; 'integers': 0.09; 'iterate': 0.09; 'literal': 0.09; 'skip:\\ 10': 0.09; 'subject:How': 0.10; '")"': 0.16; '-tkc': 0.16; 'although,': 0.16; 'bracket': 0.16; 'means.': 0.16; 'roy': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; 'utterly': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'example': 0.22; 'to:name:python-list@python.org': 0.22; 'header:Received:8': 0.24; 'sort': 0.25; 'shown': 0.26; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'tim': 0.29; 'characters': 0.30; 'chase': 0.31; "d'aprano": 0.31; 'steven': 0.31; '-----': 0.33; 'comment': 0.34; 'subject:the': 0.34; 'but': 0.35; 'two': 0.37; 'list': 0.37; 'email addr:python.org': 0.37; 'awesome': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'expression': 0.60; 'received:98.137': 0.60; 'first': 0.61; 're:': 0.63; 'july': 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'email name:python-list': 0.65; 'close': 0.67; 'header:Reply-To:1': 0.67; 'received:gq1.yahoo.com': 0.68; 'received:mail.gq1.yahoo.com': 0.68; 'smith': 0.68; 'useful.': 0.68; 'received:98.136': 0.69; 'jul': 0.74; 'article': 0.77; 'as:': 0.81; 'commenting': 0.84; 'received:bullet.mail.gq1.yahoo.com': 0.84; 'skip:: 20': 0.84; 'capture': 0.91 X-Yahoo-Newman-Property: ymail-4 X-Yahoo-Newman-Id: 79043.32115.bm@omp1018.mail.gq1.yahoo.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1405091890; bh=B1mp0oWr+tt2wuOc35vb7puGSEVpr5Em0Gl7ixzisX8=; h=References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=xBgXWywod+pWkSuZgZERAzRTTRoSSZVozugXIXD/eH9lH5RQyDOen4a0yM9em3/qbdQZEeU69o5FLv01jTtita/fuKP/H0Y/axIbniTBuCRrWrjlbBz5kYJAlYFcAhFfzXjJzPEFSBsWjUuYbpd2dSVfyVjSJ/ymVva9KCJYl3Y= X-YMail-OSG: pp6jgZIVM1kUiQsCxwkbS7y8dqH26wsN6lxVPGQJljeUNHV R6oizoAIlaHQSyY.0n0g6IgwdwRuXEHqzG49ExRZnIHH2GAk8BMbBAn9AMv8 Yr8cNmt4h3sKRZkD1s11TRuiSM3pWY1VVKlDmg00Zd6Mz38F5s6BWE2.koQ6 Sgo0R4OjtHDXXs5O8W9PpGCwz7Rfgq3GKuB.fOzLqdTFU4_8uCmWZr6npYrW Y2EAUwxcz7AF8T8Wg8bwXhg68dA_Q7Po5ZPJGJ1GtFr1Jz3G7VzkFe1Qdi1i G3PlbiQhZPd_ZdMhIkhEe9Xdm8ruUXrNxU0gwPvXA3IZnwUEZrn2lptBjzaW s3JQSyqFX_XfGLcSIAEodR1NqkRkP4ZKhDfNpgKRnNodxXM.z9_Bo3vvOzPd nd8PBU5gxL3UejjCk7YUBhEDxc.kc1F_T_qR7duZ.1x92xQpvsTpfCIDK1p0 V0rIdQr5ToNgXEF02aekmOmxcUtm6EK4utKm6LQ2spi6noUa0OttjVp3OWc7 87jjQR2wt7gYFvySuQafwArNHthjwAB46Mwq59vnQS5CTaIBvs_0XSX4.qxo - X-Rocket-MIMEInfo: 002.001, CgotLS0tLSBPcmlnaW5hbCBNZXNzYWdlIC0tLS0tCgo.IEZyb206IFN0ZXZlbiBEJ0FwcmFubyA8c3RldmVAcGVhcndvb2QuaW5mbz4KPiBUbzogcHl0aG9uLWxpc3RAcHl0aG9uLm9yZwo.IENjOiAKPiBTZW50OiBGcmlkYXksIEp1bHkgMTEsIDIwMTQgMTE6MDQgQU0KPiBTdWJqZWN0OiBSZTogSG93IHRvIGRlY2lwaGVyIDpyZS5zcGxpdChyIihcKFwoW14pXStcKVwpKSIgaW4gdGhlIGV4YW1wbGUKPiAKPiBPbiBUaHUsIDEwIEp1bCAyMDE0IDIzOjMzOjI3IC0wNDAwLCBSb3kgU21pdGggd3JvdGU6Cj4gCj4BMAEBAQE- X-Mailer: YahooMailWebService/0.8.194.680 References: <981c1f5f-2c19-4efc-8397-796bde07f39b@googlegroups.com> <53bfa881$0$2746$c3e8da3$76491128@news.astraweb.com> Date: Fri, 11 Jul 2014 08:18:09 -0700 From: Albert-Jan Roskam Subject: Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example To: Steven D'Aprano , "python-list@python.org" In-Reply-To: <53bfa881$0$2746$c3e8da3$76491128@news.astraweb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Albert-Jan Roskam 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1405092218 news.xs4all.nl 2912 [2001:888:2000:d::a6]:52835 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74359 =0A=0A----- Original Message -----=0A=0A> From: Steven D'Aprano =0A> To: python-list@python.org=0A> Cc: =0A> Sent: Friday, July 1= 1, 2014 11:04 AM=0A> Subject: Re: How to decipher :re.split(r"(\(\([^)]+\)\= ))" in the example=0A> =0A> On Thu, 10 Jul 2014 23:33:27 -0400, Roy Smith w= rote:=0A> =0A>> In article ,=0A>> =A0 Tim Chase wrote:=0A>> = =0A>>> On 2014-07-10 22:18, Roy Smith wrote:=0A>>> > > Outside this are \= ( and \): these are literal opening =0A> and closing=0A>>> > > bracket cha= racters. So:=0A>>> > > =0A>>> > >=A0 =A0 \(\([^)]+\)\)=0A>>> >=0A>>> > = although, even better would be to use to utterly awesome=0A>>> >> re.VERBO= SE=0A>>> > flag, and write it as:=0A>>> > =0A>>> >=A0 =A0 =A0 \({2} [^)]= + \){2}=0A>>> =0A>>> Or heck, use a multi-line verbose expression and comm= ent it for=0A>>> clarity:=0A>>> =0A>>> =A0 r =3D re.compile(r"""=0A>>> = =A0 =A0 (=A0 =A0 =A0 =A0 =A0 =A0 # begin a capture group=0A>>> =A0 =A0 =A0= \({2}=A0 =A0 =A0 # two literal "(" characters [^)]+=A0 =0A> =A0 =A0 # on= e or more=0A>>> =A0 =A0 =A0 non-close-paren characters \){2}=A0 =A0 =A0 # = two literal =0A> ")"=0A>>> =A0 =A0 =A0 characters=0A>>> =A0 =A0 )=A0 =A0 = =A0 =A0 =A0 =A0 # close the capture group """, =0A> re.VERBOSE)=0A>>> =0A>>= > -tkc=0A>> =0A>> Ugh.=A0 That reminds me of the classic commenting anti-= pattern:=0A> =0A> The sort of dead-simple commenting shown below is not jus= t harmless but =0A> can be *critically important* for beginners, who otherw= ise may not know =0A> what "l =3D []" means.=0A> =0A>> l =3D []=A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 # create an empty list =0A>> for i in range(10):= =A0 =A0 # iterate over the first 10 integers=0A>> =A0 =A0 l.append(i)=A0 = =A0 =A0 =A0 # append each one to the list=0A> =0A=0AAnything better than t= his hideous type of commenting: (?#...), e.g=0A>>> re.match("(19|20)[0-9]{2= }(?#year)-[0-9]{2}(?#month)", "2010-12")=0ASame thing for the 'limsux' modi= fiers, although *maybe* they can be useful.