[issue14460] In re's positive lookbehind assertion repetition works

Tim Peters report at bugs.python.org
Thu Jun 26 21:24:17 CEST 2014


Tim Peters added the comment:

I would not call this a bug - it's just usually a silly thing to do ;-)

Note, e.g., that p{N} is shorthand for writing p N times.  For example, p{4} is much the same as pppp (but not exactly so in all cases; e.g., if `p` happens to contain a capturing group, the numbering of all capturing groups will differ between those two spellings).

A successful assertion generally matches an empty string (does not advance the position being looked at in the target string).  So, e.g., if we're at some point in the target string where

(?<=a)

matches, then

(?<=a)(?<=a)

will also match at the same point, and so will

(?<=a)(?<=a)(?<=a)

and

(?<=a)(?<=a)(?<=a)(?<=a)

and so on & so on.  The position in the target string never changes, so each redundant assertion succeeds too.  So (?<=a){N} _should_ match there too.

> It works like there are 10 letters "a" before letter "b".

It's much more like you're asking whether "a" appears before "b", but are rather pointlessly asking the same question 10 times ;-)

----------
nosy: +tim.peters

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14460>
_______________________________________


More information about the Python-bugs-list mailing list