Path: csiph.com!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'enabling': 0.05; 'skip:` 10': 0.05; 'transform': 0.05; 'incompatible': 0.07; 'matches': 0.07; 'table.': 0.07; 'python': 0.09; 'backwards': 0.09; 'janvier': 0.09; 'subject:ignore': 0.09; 'to:addr:comp.lang.python': 0.09; 'unicode,': 0.09; 'cc:addr :python-list': 0.10; 'library': 0.15; 'dec': 0.15; '3.3,': 0.16; 'ascii,': 0.16; 'german.': 0.16; 'insensitive': 0.16; 'lowercase': 0.16; 'match:': 0.16; 'matching.': 0.16; 'roy': 0.16; 'sharp': 0.16; 'subject:case': 0.16; 'uppercase': 0.16; '\xc3\xa9crit\xc2\xa0:': 0.16; 'wrote:': 0.17; 'unicode': 0.17; '(in': 0.18; '>>>': 0.18; 'equivalent': 0.20; 'addition,': 0.21; 'not,': 0.21; 'posted': 0.22; 'cc:2**0': 0.23; 'matching': 0.23; 'originally': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'supported': 0.26; 'first,': 0.27; 'rules': 0.27; 'converting': 0.27; 'correct': 0.28; "d'aprano": 0.29; 'enforce': 0.29; 'header,': 0.29; 'steven': 0.29; 'url:mailman': 0.29; '"the': 0.29; 'probably': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'mode': 0.30; 'code': 0.31; '(and': 0.32; 'problem.': 0.32; 'url:python': 0.32; '-----': 0.32; 'german': 0.32; "skip:' 20": 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'affects': 0.33; 'curious': 0.33; 'point,': 0.33; 'typically': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'so,': 0.35; 'doing': 0.35; 'expected': 0.35; 'sometimes': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'das': 0.36; 'skip:u 20': 0.36; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'correctly': 0.37; 'skip:v 20': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'things': 0.38; 'nothing': 0.38; 'instead': 0.39; 'build': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'url:mail': 0.40; 'think': 0.40; 'from:no real name:2**0': 0.60; 'lower': 0.61; 'mentioned': 0.63; 'more': 0.63; 'show': 0.63; 'wanting': 0.65; 'capital': 0.68; '8bit%:10': 0.69; 'smith': 0.71; 'unusual': 0.71; '2013': 0.84; 'check)': 0.84; 'excellent.': 0.84; 'flag.': 0.84; 'fonts': 0.84; 'grosse': 0.84; 'sensitivity': 0.84; 'serious': 0.98 Newsgroups: comp.lang.python Date: Wed, 2 Jan 2013 06:17:04 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=178.198.163.217; posting-account=ung4FAoAAAC46zhHJ0Nsnuox7M5gDvs_ References: <50e02485$0$3109$ba620e4c@news.skynet.be> <50e262a1$0$30003$c3e8da3$5496439d@news.astraweb.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 178.198.163.217 MIME-Version: 1.0 Subject: Re: ignore case only for a part of the regex? From: wxjmfauth@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 236 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357136227 news.xs4all.nl 6858 [2001:888:2000:d::a6]:37221 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35987 Le mercredi 2 janvier 2013 00:09:45 UTC+1, Vlastimil Brom a =C3=A9crit=C2= =A0: > 2013/1/1 Steven D'Aprano : >=20 > > On Sun, 30 Dec 2012 10:20:19 -0500, Roy Smith wrote: >=20 > > >=20 > >> The way I would typically do something like this is build my regexes i= n >=20 > >> all lower case and .lower() the text I was matching against them. I'm >=20 > >> curious what you're doing where you want to enforce case sensitivity i= n >=20 > >> one part of a header, but not in another. >=20 > > >=20 > > Well, sometimes you have things that are case sensitive, and other thin= gs >=20 > > which are not, and sometimes you need to match them at the same time. I >=20 > > don't think this is any more unusual than (say) wanting to match an >=20 > > otherwise lowercase word whether or not it comes at the start of a >=20 > > sentence: >=20 > > >=20 > > "[Pp]rogramming" >=20 > > >=20 > > is conceptually equivalent to "match case-insensitive `p`, and case- >=20 > > sensitive `rogramming`". >=20 > > >=20 > > >=20 > > By the way, although there is probably nothing you can (easily) do abou= t >=20 > > this prior to Python 3.3, converting to lowercase is not the right way = to >=20 > > do case-insensitive matching. It happens to work correctly for ASCII, b= ut >=20 > > it is not correct for all alphabetic characters. >=20 > > >=20 > > >=20 > > py> 'Stra=C3=9Fe'.lower() >=20 > > 'stra=C3=9Fe' >=20 > > py> 'Stra=C3=9Fe'.upper() >=20 > > 'STRASSE' >=20 > > >=20 > > >=20 > > The right way is to casefold first, then match: >=20 > > >=20 > > py> 'Stra=C3=9Fe'.casefold() >=20 > > 'strasse' >=20 > > >=20 > > >=20 > > Curiously, there is an uppercase =C3=9F in old German. In recent years = some >=20 > > typographers have started using it instead of SS, but it's still rare, >=20 > > and the official German rules have =C3=9F transform into SS and vice ve= rsa. >=20 > > It's in Unicode, but few fonts show it: >=20 > > >=20 > > py> unicodedata.lookup('LATIN CAPITAL LETTER SHARP S') >=20 > > '=E1=BA=9E' >=20 > > >=20 > > >=20 > > >=20 > > -- >=20 > > Steven >=20 > > -- >=20 > > http://mail.python.org/mailman/listinfo/python-list >=20 >=20 >=20 > Hi, >=20 > just for completeness, the mentioned regex library can take care of >=20 > casfolding in case insensitive matching (in all supported versions: >=20 > Python 2.5-2.7 and 3.1-3.3); i.e.: >=20 > # case sensitive match: >=20 > >>> for m in regex.findall(ur"Stra=C3=9Fe", u" STRA=C3=9FE STRASSE STRA= =E1=BA=9EE Strasse Stra=C3=9Fe "): print m >=20 > ... >=20 > Stra=C3=9Fe >=20 >=20 >=20 > # case insensitive match: >=20 > >>> for m in regex.findall(ur"(?i)Stra=C3=9Fe", u" STRA=C3=9FE STRASSE ST= RA=E1=BA=9EE Strasse Stra=C3=9Fe "): print m >=20 > ... >=20 > STRA=C3=9FE >=20 > STRA=E1=BA=9EE >=20 > Stra=C3=9Fe >=20 >=20 >=20 > # case insensitive match with casefolding: >=20 > >>> for m in regex.findall(ur"(?if)Stra=C3=9Fe", u" STRA=C3=9FE STRASSE S= TRA=E1=BA=9EE Strasse Stra=C3=9Fe "): print m >=20 > ... >=20 > STRA=C3=9FE >=20 > STRASSE >=20 > STRA=E1=BA=9EE >=20 > Strasse >=20 > Stra=C3=9Fe >=20 > >>> >=20 > >>> >=20 >=20 >=20 > # after enabling the backwards incompatible modern matching behaviour, >=20 > casefolding is by default turned on for case insensitive matches >=20 > >>> for m in regex.findall(ur"(?V1i)Stra=C3=9Fe", u" STRA=C3=9FE STRASSE = STRA=E1=BA=9EE Strasse Stra=C3=9Fe "): print m >=20 > ... >=20 > STRA=C3=9FE >=20 > STRASSE >=20 > STRA=E1=BA=9EE >=20 > Strasse >=20 > Stra=C3=9Fe >=20 > >>> >=20 >=20 >=20 >=20 >=20 > As a small addition, the originally posted pattern r'^Msg-(?:(?i)id):' >=20 > would actually work as expected in this modern matching mode in regex >=20 > - enabled with the V1 flag. In this case the flag-setting (?i) only >=20 > affects the following parts of the pattern, not the whole pattern like >=20 > in the current "re" and V0-compatibility-mode "regex" >=20 >=20 >=20 > >>> regex.findall(r"(?V1)Msg-(?:(?i)id):", "the regex should match Msg-i= d:, Msg-Id:, ... but not msg-id:, MSG-ID: and so on") >=20 > ['Msg-id:', 'Msg-Id:'] >=20 ------ Vlastimil: Excellent. ----- Steven: ..." It's in Unicode, but few fonts show it:" ... Das grosse Eszett is a member of the unicode subsets MES-2, WGL-4. Good - serious - fonts are via OpenType MES-2 or WGL-4 compliant. So, it is a no problem. I do not know (and I did not check) if the code point, 1e9e, is part of the utf32 table. jmf