Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74359
| References | (1 earlier) <mailman.11746.1405042179.18130.python-list@python.org> <roy-CC0052.22182710072014@news.panix.com> <mailman.11747.1405046292.18130.python-list@python.org> <roy-AAB0F1.23332710072014@news.panix.com> <53bfa881$0$2746$c3e8da3$76491128@news.astraweb.com> |
|---|---|
| Date | 2014-07-11 08:18 -0700 |
| From | Albert-Jan Roskam <fomcl@yahoo.com> |
| Subject | Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11761.1405092218.18130.python-list@python.org> (permalink) |
----- Original Message -----
> From: Steven D'Aprano <steve@pearwood.info>
> To: python-list@python.org
> Cc:
> Sent: Friday, July 11, 2014 11:04 AM
> Subject: Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example
>
> On Thu, 10 Jul 2014 23:33:27 -0400, Roy Smith wrote:
>
>> In article <mailman.11747.1405046292.18130.python-list@python.org>,
>> Tim Chase <python.list@tim.thechases.com> 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:
>
> The sort of dead-simple commenting shown below is not just harmless but
> can be *critically important* for beginners, who otherwise may not know
> what "l = []" means.
>
>> 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
>
Anything better than this hideous type of commenting: (?#...), e.g
>>> re.match("(19|20)[0-9]{2}(?#year)-[0-9]{2}(?#month)", "2010-12")
Same thing for the 'limsux' modifiers, although *maybe* they can be useful.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
How to decipher :re.split(r"(\(\([^)]+\)\))" in the example fl <rxjwg98@gmail.com> - 2014-07-10 08:37 -0700
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example Peter Otten <__peter__@web.de> - 2014-07-10 18:49 +0200
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example MRAB <python@mrabarnett.plus.com> - 2014-07-10 18:01 +0100
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example Joel Goldstick <joel.goldstick@gmail.com> - 2014-07-10 13:05 -0400
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example Albert-Jan Roskam <fomcl@yahoo.com> - 2014-07-10 12:15 -0700
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example Cameron Simpson <cs@zip.com.au> - 2014-07-11 11:29 +1000
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example Roy Smith <roy@panix.com> - 2014-07-10 22:18 -0400
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example Tim Chase <python.list@tim.thechases.com> - 2014-07-10 21:37 -0500
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example Roy Smith <roy@panix.com> - 2014-07-10 23:33 -0400
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example Chris Angelico <rosuav@gmail.com> - 2014-07-11 14:31 +1000
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example alister <alister.nospam.ware@ntlworld.com> - 2014-07-11 08:00 +0000
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example Steven D'Aprano <steve@pearwood.info> - 2014-07-11 09:04 +0000
Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example Albert-Jan Roskam <fomcl@yahoo.com> - 2014-07-11 08:18 -0700
csiph-web