Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87218
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python.list@tim.thechases.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.042 |
| X-Spam-Evidence | '*H*': 0.92; '*S*': 0.00; 'string': 0.09; 'identifier': 0.09; 'underscore': 0.09; "'+'": 0.16; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'identifier,': 0.16; 'subject:class': 0.16; 'underscore.': 0.16; 'width,': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'character': 0.29; 'thus': 0.29; 'tim': 0.29; "doesn't": 0.30; 'matching': 0.30; 'work.': 0.31; 'letter.': 0.31; "can't": 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'acceptable': 0.36; 'should': 0.36; 'received:10': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'even': 0.60; 'further': 0.61; 'first': 0.61; 'more': 0.64; '8bit%:21': 0.69; '"one': 0.84; 'characters,': 0.84; 'pardon': 0.84; 'subject:Letter': 0.93 |
| X-Sender-Id | wwwh|x-authuser|tim@thechases.com |
| X-Sender-Id | wwwh|x-authuser|tim@thechases.com |
| X-MC-Relay | Neutral |
| X-MailChannels-SenderId | wwwh|x-authuser|tim@thechases.com |
| X-MailChannels-Auth-Id | wwwh |
| X-MC-Loop-Signature | 1425914185363:3859495736 |
| X-MC-Ingress-Time | 1425914185363 |
| Date | Mon, 9 Mar 2015 10:17:42 -0500 |
| From | Tim Chase <python.list@tim.thechases.com> |
| To | python-list@python.org |
| Subject | Re: Letter class in re |
| In-Reply-To | <54FDAE5F.10504@rece.vub.ac.be> |
| References | <54FD74BA.8010803@rece.vub.ac.be> <mdjt75$jpu$1@ger.gmane.org> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> <20150309075017.7076718a@bigbox.christie.dr> <54FDAE5F.10504@rece.vub.ac.be> |
| X-Mailer | Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-AuthUser | tim@thechases.com |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.223.1425916877.21433.python-list@python.org> (permalink) |
| Lines | 47 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1425916877 news.xs4all.nl 2965 [2001:888:2000:d::a6]:42305 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:87218 |
Show key headers only | View raw
On 2015-03-09 15:29, Antoon Pardon wrote:
> Op 09-03-15 om 13:50 schreef Tim Chase:
> >> (?:(?!_|\d)\w)\w+
> > If you don't have to treat it as an atom, you can simplify that to
> > just
> >
> > (?!_|\d)\w+
> >
> > which just means that the first character can't be an underscore
> > or digit.
> >
> > Though for a Py3 identifier, the underscore is acceptable as a
> > first character ("__init__"), so you can simplify it even further
> > to just
> >
> > (?!\d)\w+
>
> No that doesn't work. To begin with my attempt above shoud have
> been:
>
> (?:(?!_|\d)\w)\w*
Did you actually test my suggestion? The "(?!\d)\w+" means "one or
more Word characters, but the first one can't be a digit" because
the "(?!...)" is zero-width. This should match single-character
strings including a single underscore.
> because an identifier can just be one letter. So when change the '+'
> into a "*' in your suggestion I get this:
>
> >>> r = re.compile(r"(?!\d)\w*")
> >>> r.match('√')
> <_sre.SRE_Match object; span=(0, 0), match=''>
>
> But the √ is not a letter.
Notice that you match an empty string there because the (?!\d) is
zero width, and thus you match 0-or-more-word-characters by matching
nothing. Try either anchoring it with a "$" at the end to see that
it doesn't really match.
-tkc
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Letter class in re Tim Chase <python.list@tim.thechases.com> - 2015-03-09 10:17 -0500
csiph-web