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


Groups > comp.lang.python > #39710

Re: 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!eweka.nl!lightspeed.eweka.nl!194.109.133.83.MISMATCH!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; 'source.': 0.05; 'character,': 0.07; 'emulate': 0.07; 'matches': 0.07; '(0,': 0.09; 'restriction': 0.09; ';-)': 0.11; ':-)': 0.13; 'sat,': 0.15; "(it's": 0.16; '1),': 0.16; '[*]': 0.16; 'benefit.': 0.16; 'better?': 0.16; 'enough.': 0.16; 'fold': 0.16; 'folding': 0.16; 'forbid': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'fuzzy': 0.16; 'integers,': 0.16; 'iteration': 0.16; 'iteration.': 0.16; 'matching.': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; "module's": 0.16; 'problem).': 0.16; 'regex,': 0.16; 'repetitions': 0.16; 'so!': 0.16; 'subject:case': 0.16; 'subject:handling': 0.16; 'subject:unicode': 0.16; 'wrote:': 0.17; 'implementing': 0.17; 'unicode': 0.17; 'tests': 0.18; '>>>': 0.18; 'input': 0.18; 'feb': 0.19; 'module': 0.19; '(not': 0.20; 'not,': 0.21; 'either.': 0.22; "i'd": 0.22; 'matching': 0.23; "i've": 0.23; 'seems': 0.23; 'second': 0.24; 'so.': 0.24; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(see': 0.27; 'done.': 0.27; 'i.e.': 0.27; 'run': 0.28; 'character.': 0.29; 'character': 0.29; 'source': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'e.g.': 0.30; 'basic': 0.30; 'figure': 0.30; 'code': 0.31; 'asking': 0.32; 'could': 0.32; 'certain': 0.33; 'goes': 0.33; 'cases,': 0.33; 'text,': 0.33; 'problem': 0.33; 'to:addr:python- list': 0.33; 'that,': 0.34; "can't": 0.34; 'done': 0.34; 'fail': 0.35; 'open': 0.35; 'pm,': 0.35; 'but': 0.36; 'be.': 0.36; 'characters': 0.36; "i'll": 0.36; 'should': 0.36; 'possible': 0.37; 'ok,': 0.37; 'supporting': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'planning': 0.38; 'supports': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'end': 0.40; 'think': 0.40; 'places': 0.61; 'first': 0.61; 'series': 0.63; 'more': 0.63; 'within': 0.64; 'behavior': 0.64; 'middle': 0.66; 'header:Reply-To:1': 0.68; 'positions': 0.68; 'reply-to:no real name:2**0': 0.72; '2013': 0.84; '3.13': 0.84; 'actually,': 0.84; 'easier,': 0.84; 'reply- to:addr:python.org': 0.84; 'hand,': 0.97
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=XeZXOvF5 c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=_vX2mLoUpDQA:10 a=pYDWctdyWDYA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=PrWc515xQVYA:10 a=NK5LRLMChblGsaCe9w0A:9 a=QEXdDO2ut3YA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Sat, 23 Feb 2013 20:23:29 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130215 Thunderbird/17.0.3
MIME-Version 1.0
To python-list@python.org
Subject Re: Correct handling of case in unicode and regexps
References <CABicbJLzQ9AHrGuaooiBRk45U5CHZYw6CodJFiQvAuF4+7kToA@mail.gmail.com> <CAHzaPEMmSExoFunOp_OyRCEOKE-+WzEO-hdb61DUiZFnzOG_rw@mail.gmail.com> <CABicbJJ0RoyQVdX9Hyd-fYeumS4faH2TVpYHiMwW0MRuPZUL8g@mail.gmail.com> <CABicbJ+fQW0og8rJsL5Bio_uTNCUtNwEN2MAtSdWmg49Zw7r8Q@mail.gmail.com> <5128FF37.7060500@mrabarnett.plus.com> <CABicbJJ0aPB-bytZo9g8OwmP7RTKmVkKoz=uxqz6XCSKecR2eA@mail.gmail.com> <51290699.8050209@mrabarnett.plus.com> <CABicbJJyF9OLBhB8dJCHjE30KfkUsBAwch5GpEfEby8X19=JYg@mail.gmail.com>
In-Reply-To <CABicbJJyF9OLBhB8dJCHjE30KfkUsBAwch5GpEfEby8X19=JYg@mail.gmail.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
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.2377.1361651008.2939.python-list@python.org> (permalink)
Lines 63
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361651008 news.xs4all.nl 6843 [2001:888:2000:d::a6]:53806
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39710

Show key headers only | View raw


On 2013-02-23 18:57, Devin Jeanpierre wrote:
> On Sat, Feb 23, 2013 at 1:12 PM, MRAB <python@mrabarnett.plus.com>
> wrote:
>> The basic rule is that a series of characters in the regex must
>> match a series of characters in the text, with no partial matches
>> in either.
>>
>> For example, 'ss' can match 'ß', but 's' can't match 'ß' because
>> that would be matching part of 'ß'.
>>
>> In a regex like 's+', you're asking it to match one or more
>> repetitions of 's', but that would mean that 's' would have to
>> match part of 'ß' in the first iteration and the remainder of 'ß'
>> in the second iteration.
>
> That makes sense. I'll have to think about this and run some tests
> through regex, as well.
>
>> Although it's theoretically possible to do that, the code is
>> already difficult enough. The cost outweighs the potential
>> benefit.
>>
>> If you'd like to have a go at implementing it, the code _is_ open
>> source. :-)
>
> Actually, the reason it's relevant to me is that I'm reimplementing
> the re module using a more automata theoretic approach (it's my
> second attack at the problem). Also, I've read the _sre source code
> and it's unpleasant. Is regex much better?
>
I like to think so! ;-)

Part of the problem may be that it also supports fuzzy (approximate)
matching.

> At least the way I'm planning on going about it, supporting this is
> easier, as long as one can figure out what it means to match halfway
> inside a ß. Since case folding is a homomorphism*, I can case fold
> the regex** and case fold the input and then I'm done. Case folding
> of the input can be done character by character, and to emulate the
> regex module behavior I'd need to check at certain places whether or
> not I'm in the middle of a casefolding expansion, and fail if so. On
> the other hand, if I don't emulate the regex module's behavior in at
> least some cases, I'd need to figure out what the value of a match
> of 's' against 'ß' would be.
>
It seems like a reasonable restriction to me that start and end
positions should be integers, i.e. forbid partial matches within a
character.

This means that matching '(ss)' against 'ß' would be OK, as would '(s+)'
against 'ß', but '(s)' or '(s)(s)' against 'ß' would not, otherwise you
could get:

>>> match('(s)', 'ß').span(0)
(0, 0.5)
>>> match('(s)(s)', 'ß').span(0, 1, 2)
((0, 1), (0, 0.5), (0.5, 1)).

> [*]  i.e. it can be done character by character (see Unicode 3.13
> Default Case Algorithms) [**] Not as trivial as it sounds, but still
>  easy. [ßa-z] goes to e.g. [a-z]|ss (not [ssa-z]).
>

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


Thread

Re: Correct handling of case in unicode and regexps MRAB <python@mrabarnett.plus.com> - 2013-02-23 20:23 +0000

csiph-web