Prev: Getting pyparsing to backtrack
Next: markmin 0.1
From: andrew cooke on 5 Jul 2010 20:10 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 5 Jul 2010 20:56 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 5 Jul 2010 21:25 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 5 Jul 2010 21:38 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 6 Jul 2010 06:37 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 |