By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,763 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,763 IT Pros & Developers. It's quick & easy.

regexp weirdness (bug?)

P: n/a
Here's the session log:
_re_pair="(?(plus).|-)"
_re1=("(?P<plus>\+)"+_re_pair)
_re2=("((?P<plus>\+))"+_re_pair)
_re3=("(?:(?P<plus>\+))"+_re_pair)
_re4="(%s)"%_re3
import re
print [re.match(_re, "+a") and 'match' for _re in [_re1, _re2,

_re3, _re4]]
['match', None, 'match', None]

this is not the supposed behaivour. all theese patterns should match,
right?

Jul 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
* Sergey Schetinin wrote:
Here's the session log:
_re_pair="(?(plus).|-)"
_re1=("(?P<plus>\+)"+_re_pair)
_re2=("((?P<plus>\+))"+_re_pair)
_re3=("(?:(?P<plus>\+))"+_re_pair)
_re4="(%s)"%_re3
import re
print [re.match(_re, "+a") and 'match' for _re in [_re1, _re2,

_re3, _re4]]
['match', None, 'match', None]

this is not the supposed behaivour. all theese patterns should match,
right?


No, I suppose they shouldn't compile.
_re_pair should be (?P=plus).

nd

Jul 18 '05 #2

P: n/a
André Malo wrote:
No, I suppose they shouldn't compile.
_re_pair should be (?P=plus).


the (?(NAME)RE|RE) form was added in 2.4.

looks like a bug to me; the "plus" group is set to "+" in all four cases, so the
final pattern should match. but I might be missing something...

</F>

Jul 18 '05 #3

P: n/a
* Fredrik Lundh wrote:
André Malo wrote:
No, I suppose they shouldn't compile.
_re_pair should be (?P=plus).


the (?(NAME)RE|RE) form was added in 2.4.

looks like a bug to me; the "plus" group is set to "+" in all four cases,
so the
final pattern should match. but I might be missing something...


Uh, yeah, I'm not up to date and still using 2.3 ;)
However, I've investigated a bit in the sre code and found this in
sre_compile.py:

150 elif op is GROUPREF_EXISTS:
151 emit(OPCODES[op])
152 emit((av[0]-1)*2)
153 skipyes = _len(code); emit(0)
154 _compile(code, av[1], flags)

Sergey, can you please change line 152 in your sre_compile.py to

emit(av[0]-1)

and see if it works then? (The matcher also multiplies with 2, so this is
most likely the bug). But it's just theoretically, since I don't have
python 2.4 installed for a test :)

nd
Jul 18 '05 #4

P: n/a
it's line #159 here, but it did work! thanks. so it IS a bug?

Jul 18 '05 #5

P: n/a
Sergey Schetinin wrote:
it's line #159 here, but it did work! thanks. so it IS a bug?


sure looks like one. please report it here:

http://sourceforge.net/tracker/?grou...70&atid=105470

</F>

Jul 18 '05 #6

P: n/a
* Fredrik Lundh wrote:
Sergey Schetinin wrote:
it's line #159 here, but it did work! thanks. so it IS a bug?


sure looks like one. please report it here:

http://sourceforge.net/tracker/?grou...70&atid=105470


done :)

nd
--
"Das Verhalten von Gates hatte mir bewiesen, dass ich auf ihn und seine
beiden Gefährten nicht zu zählen brauchte" -- Karl May, "Winnetou III"

Im Westen was neues: <http://pub.perlig.de/books.html#apache2>
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.