Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example Date: Thu, 10 Jul 2014 23:33:27 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 33 Message-ID: References: <981c1f5f-2c19-4efc-8397-796bde07f39b@googlegroups.com> NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1405049608 16719 127.0.0.1 (11 Jul 2014 03:33:28 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 11 Jul 2014 03:33:28 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: csiph.com comp.lang.python:74340 In article , Tim Chase wrote: > On 2014-07-10 22:18, Roy Smith wrote: > > > Outside this are \( and \): these are literal opening and closing > > > bracket characters. So: > > > > > > \(\([^)]+\)\) > > > > although, even better would be to use to utterly awesome > >> re.VERBOSE > > flag, and write it as: > > > > \({2} [^)]+ \){2} > > Or heck, use a multi-line verbose expression and comment it for > clarity: > > r = re.compile(r""" > ( # begin a capture group > \({2} # two literal "(" characters > [^)]+ # one or more non-close-paren characters > \){2} # two literal ")" characters > ) # close the capture group > """, re.VERBOSE) > > -tkc Ugh. That reminds me of the classic commenting anti-pattern: l = [] # create an empty list for i in range(10): # iterate over the first 10 integers l.append(i) # append each one to the list