From: andrew cooke on

As ever, I guess it's most likely I've misunderstood something, but in
Python 2.6 lookback seems to actually be lookahead. All the following
tests pass:

from re import compile

assert compile('(a)b(?<=(?(2)x|c))(c)').match('abc')
assert not compile('(a)b(?<=(?(2)b|x))(c)').match('abc')
assert compile('(a)b(?<=(?(1)c|x))(c)').match('abc')

assert compile('(a)b(?=(?(2)x|c))(c)').match('abc')
assert not compile('(a)b(?=(?(2)b|x))(c)').match('abc')
assert compile('(a)b(?=(?(1)c|x))(c)').match('abc')

But it seems to me that the first block should fail, because they
check the match *before* the point in question.

Note that without group references these work as I would expected:

assert compile('(a)b(?<=b)(c)').match('abc')
assert not compile('(a)b(?<=c)(c)').match('abc')

assert not compile('(a)b(?=b)(c)').match('abc')
assert compile('(a)b(?=c)(c)').match('abc')

in which lookback does indeed lookback (note the asymmetry, while the
first examples were symmetrical).

What am I missing this time? :o(

Thanks,
Andrew

From: MRAB on
andrew cooke wrote:
> As ever, I guess it's most likely I've misunderstood something, but in
> Python 2.6 lookback seems to actually be lookahead. All the following
> tests pass:
>
> from re import compile
>
> assert compile('(a)b(?<=(?(2)x|c))(c)').match('abc')
> assert not compile('(a)b(?<=(?(2)b|x))(c)').match('abc')
> assert compile('(a)b(?<=(?(1)c|x))(c)').match('abc')
>
> assert compile('(a)b(?=(?(2)x|c))(c)').match('abc')
> assert not compile('(a)b(?=(?(2)b|x))(c)').match('abc')
> assert compile('(a)b(?=(?(1)c|x))(c)').match('abc')
>
> But it seems to me that the first block should fail, because they
> check the match *before* the point in question.
>
Both the first and third should fail, but they pass.

> Note that without group references these work as I would expected:
>
> assert compile('(a)b(?<=b)(c)').match('abc')
> assert not compile('(a)b(?<=c)(c)').match('abc')
>
> assert not compile('(a)b(?=b)(c)').match('abc')
> assert compile('(a)b(?=c)(c)').match('abc')
>
> in which lookback does indeed lookback (note the asymmetry, while the
> first examples were symmetrical).
>
> What am I missing this time? :o(
>
Nothing. It's a bug. :-(
From: andrew cooke on
On Jul 5, 8:56 pm, MRAB <pyt...(a)mrabarnett.plus.com> wrote:
> andrew cooke wrote:
> > What am I missing this time? :o(
> Nothing. It's a bug. :-(

Sweet :o)

Thanks - do you want me to raise an issue or will you?

Cheers,
Andrew
From: MRAB on
andrew cooke wrote:
> On Jul 5, 8:56 pm, MRAB <pyt...(a)mrabarnett.plus.com> wrote:
>> andrew cooke wrote:
>>> What am I missing this time? :o(
>> Nothing. It's a bug. :-(
>
> Sweet :o)
>
> Thanks - do you want me to raise an issue or will you?
>
You found it. You can have the pleasure.
From: andrew cooke on
http://bugs.python.org/issue9179

On Jul 5, 9:38 pm, MRAB <pyt...(a)mrabarnett.plus.com> wrote:
> andrew cooke wrote:
> > On Jul 5, 8:56 pm, MRAB <pyt...(a)mrabarnett.plus.com> wrote:
> >> andrew cooke wrote:
> >>> What am I missing this time? :o(
> >> Nothing. It's a bug. :-(
>
> > Sweet :o)
>
> > Thanks - do you want me to raise an issue or will you?
>
> You found it. You can have the pleasure.

 | 
Pages: 1
Prev: Getting pyparsing to backtrack
Next: markmin 0.1