Changes by Serhiy Storchaka storch...@gmail.com:
--
resolution: - not a bug
stage: - resolved
status: open - closed
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20678
___
New submission from steven Michalske:
When writing a regular expression to match the following text.
d = num interesting lines: 3
1
2
3
foo
# I only want to match the interesting lines.
m = re.match(.+?: (\d+)\n((?:.+\n){\1}), d)
print(m)
# prints: None
# Expected a match object.
Matthew Barnett added the comment:
I don't know of any regex implementation that lets you do that.
--
type: behavior - enhancement
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20678
___
steven Michalske added the comment:
The RE compiler will not error out, with a back reference in there...
It treats the {\1} as a literal {\1} in the string.
In [180]: re.search((\d) fo.{\1}, '3 foo{\1}').group(0)
Out[180]: '3 foo{\x01}'
--
___
Matthew Barnett added the comment:
Yes.
If it's not a valid repeat, then it's treated as a literal.
Perl does the same.
By the way, \1 isn't a group reference; it's the same as \x01. You should
be either doubling the backslashes (\\1) or using a raw string literal
(r\1).
--