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

Roy Smith roy at
Fri Jul 11 04:18:27 CEST 2014

In article <mailman.11746.1405042179.18130.python-list at>,
 Cameron Simpson <cs at> wrote:

> Outside this are \( and \): these are literal opening and closing bracket 
> characters. So:
>    \(\([^)]+\)\)
>          Two opening brackets, then at least one character which is not a 
>          closing bracket, then two closing brackets.

This is a perfectly OK way to write this, but personally I find my eyes 
start to glaze over whenever I see things like \(\(, so I would probably 
have written it as \({2}.  I find that a little easier to read.  So, for 
the whole thing up to this point:


although, even better would be to use to utterly awesome re.VERBOSE 
flag, and write it as:

     \({2} [^)]+ \){2}

More information about the Python-list mailing list