Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'odd': 0.07; 'python3': 0.07; 'ugly': 0.07; 'e.g.,': 0.09; 'identifier': 0.09; 'parsing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'underscore': 0.09; 'url:unicode': 0.09; 'identifier.': 0.16; 'letters.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:class': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'seems': 0.21; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'unicode': 0.24; 'fine': 0.24; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'header :In-Reply-To:1': 0.27; 'am,': 0.29; 'tim': 0.29; 'included': 0.31; '>>>>': 0.31; 'assert': 0.31; 'names.': 0.31; 'received:132': 0.31; 'though.': 0.31; 'anyone': 0.31; 'class': 0.32; 'languages': 0.32; 'regular': 0.32; 'another': 0.32; "can't": 0.35; 'something': 0.35; 'no,': 0.35; 'but': 0.35; 'there': 0.35; 'sequence': 0.36; 'url:org': 0.36; 'should': 0.36; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'easy': 0.60; 'expression': 0.60; 'url:3': 0.61; 'name:': 0.61; 'such': 0.63; 'url:0': 0.67; 'frequently': 0.68; 'pardon': 0.84; 'ugly,': 0.84; 'thing,': 0.91; 'subject:Letter': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Wolfgang Maier Subject: Re: Letter class in re Date: Mon, 09 Mar 2015 14:32:43 +0100 References: <54FD74BA.8010803@rece.vub.ac.be> <20150309061736.07e0d944@bigbox.christie.dr> <54FD918B.1030702@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: px1.ruf.uni-freiburg.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 In-Reply-To: <54FD918B.1030702@rece.vub.ac.be> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1425908030 news.xs4all.nl 2901 [2001:888:2000:d::a6]:40840 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87195 On 03/09/2015 01:26 PM, Antoon Pardon wrote: > Op 09-03-15 om 12:17 schreef Tim Chase: >> On 2015-03-09 11:37, Wolfgang Maier wrote: >>> On 03/09/2015 11:23 AM, Antoon Pardon wrote: >>>> Does anyone know what regular expression to use for a sequence of >>>> letters? There is a class for alphanumerics but I can't find one >>>> for just letters, which I find odd. >>> how about [a-zA-Z] ? >> That breaks if you have Unicode letters. While ugly, since "\w" is >> composed of "letters, numbers, and underscores", you can assert that >> the "\w" you find is not a number or underscore by using >> >> (?:(?!_|\d)\w) > > So if I understand correctly the following should be a regular expression for > a python3 identifier. > > (?:(?!_|\d)\w)\w+ > No, that is not it. For one thing, a leading underscore is fine in identifier names. That is easy to fix in your expression though. Another thing are the Other_ID_Start and Other_ID_Continue categories defined in http://www.unicode.org/Public/6.3.0/ucd/PropList.txt, e.g., >>> '\u212E' '℮' >>> ℮ = 10 >>> ℮ 10 though ℮ is not included in \w. > It seems odd that one should need such an ugly expression for something that is > used rather frequently for parsing computer languages and the like. > There is str.isidentifier, which returns True if something is a valid identifier name: >>> '℮'.isidentifier() True