Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39671

Correct handling of case in unicode and regexps

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <jeanpierreda@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'case.': 0.05; 'ascii': 0.07; 'expressions': 0.07; '"work': 0.09; 'here?': 0.09; '(the': 0.15; 'folks,': 0.16; 'insensitive': 0.16; 'subject:case': 0.16; 'subject:handling': 0.16; 'subject:unicode': 0.16; 'unicode.': 0.16; '>>>': 0.18; 'module': 0.19; 'ideal': 0.20; 'addition,': 0.21; 'supposed': 0.21; "i'd": 0.22; 'work.': 0.23; "python's": 0.23; 'seems': 0.23; 'thoughts': 0.27; 'message- id:@mail.gmail.com': 0.27; 'regular': 0.27; "doesn't": 0.28; 'correct': 0.28; "i'm": 0.29; 'figure': 0.30; 'generally': 0.32; 'right?': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.34; 'received:google.com': 0.34; 'received:209.85': 0.35; 'really': 0.36; 'compare': 0.36; 'should': 0.36; 'received:209': 0.37; 'things': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'ever': 0.63; 'hear': 0.63; 'more': 0.63; 'behavior': 0.64; 'treat': 0.65; 'manner': 0.74; 'dear!': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=AoNuqnF4pRUAAGo935m1V2cK0hIQoWuJMfsofYgh3pM=; b=oZbKsakniTWdCAxXWGPKl316lW28aHtmQZI7fXwBsZUYz9N39lKrDWWZTdNl6Eycbm Vg4yNlV6ciLk+HOsl1nTyVvAagQiTgdcWeV/wlpk/2LqDx7eNqMEWX+RbUuWU1ebHtKS +It8DgVbFUVpvw/Ubr518kGqxPwN2e9Ik+gdv8eOrGPVk8R9ux4cCebj+wMWV4GZ2Xry N+Y3ZXMarcv7/wJc+zydqHpOVAgTpg1EdKyRUpS3SKYQEpy1KINbTr8wPtkKmA1/5Jgf sIKlbxJ/vq8nW5ykMRsJM8vnpdMJ09EPPZcdEYticJjCwOBf1naQE9o8K4R0p7loerCX msfg==
X-Received by 10.220.220.134 with SMTP id hy6mr7488519vcb.2.1361629617203; Sat, 23 Feb 2013 06:26:57 -0800 (PST)
MIME-Version 1.0
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date Sat, 23 Feb 2013 09:26:17 -0500
Subject Correct handling of case in unicode and regexps
To "comp.lang.python" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2347.1361629625.2939.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361629625 news.xs4all.nl 6966 [2001:888:2000:d::a6]:55630
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39671

Show key headers only | View raw


Hi folks,

I'm pretty unsure of myself when it comes to unicode. As I understand
it, you're generally supposed to compare things in a case insensitive
manner by case folding, right? So instead of a.lower() == b.lower()
(the ASCII way), you do a.casefold() == b.casefold()

However, I'm struggling to figure out how regular expressions should
treat case. Python's re module doesn't "work properly" to my
understanding, because:

    >>> a = 'ss'
    >>> b = 'ß'
    >>> a.casefold() == b.casefold()
    True
    >>> re.match(re.escape(a), b, re.UNICODE | re.IGNORECASE)
    >>> # oh dear!

In addition, it seems improbable that this ever _could_ work. Because
if it did work like that, then what would the value be of
re.match('s', 'ß', re.UNICODE | re.IGNORECASE).end() ? 0.5?

I'd really like to hear the thoughts of people more experienced with
unicode. What is the ideal correct behavior here? Or do I
misunderstand things?

-- Devin

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Correct handling of case in unicode and regexps Devin Jeanpierre <jeanpierreda@gmail.com> - 2013-02-23 09:26 -0500
  Re: Correct handling of case in unicode and regexps jmfauth <wxjmfauth@gmail.com> - 2013-02-24 11:28 -0800

csiph-web