How to decipher :re.split(r"(\(\([^)]+\)\))" in the example

Chris Angelico rosuav at gmail.com
Fri Jul 11 00:31:25 EDT 2014


On Fri, Jul 11, 2014 at 1:33 PM, Roy Smith <roy at panix.com> wrote:
>> 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

Small difference between the two. Python is designed to be a readable
language... regexps combine all the power and unreadability of machine
code with the portability of machine code.

ChrisA
exaggerating... but only a little



More information about the Python-list mailing list