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


Groups > comp.lang.python > #39672

Re: Correct handling of case in unicode and regexps

References <CABicbJLzQ9AHrGuaooiBRk45U5CHZYw6CodJFiQvAuF4+7kToA@mail.gmail.com>
Date 2013-02-23 16:11 +0100
Subject Re: Correct handling of case in unicode and regexps
From Vlastimil Brom <vlastimil.brom@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2348.1361632298.2939.python-list@python.org> (permalink)

Show all headers | View raw


2013/2/23 Devin Jeanpierre <jeanpierreda@gmail.com>:
> 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
> --
> http://mail.python.org/mailman/listinfo/python-list

Hi,
you may check the new regex implementation
https://pypi.python.org/pypi/regex
which does support casefolding in case insensitive matches (beyond
many other features and improvements comparing to re)

hth,
  vbr

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


Thread

Re: Correct handling of case in unicode and regexps Vlastimil Brom <vlastimil.brom@gmail.com> - 2013-02-23 16:11 +0100

csiph-web