[New-bugs-announce] [issue20678] re does not allow back references in {} matching operator
steven Michalske
report at bugs.python.org
Tue Feb 18 21:43:28 CET 2014
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.
print(m.groups())
# Causes Exception.
# Expected: ('3', '1\n2\n3\n')
# Works with hard coded match length.
m = re.match(".+?: (\d+)\n((?:.+\n){3})", d)
print(m.groups())
('3', '1\n2\n3\n')
Workaround it to have two regular expressions. one to extract the desired length the second to extract the interesting lines.
----------
components: Regular Expressions
messages: 211551
nosy: ezio.melotti, hardkrash, mrabarnett
priority: normal
severity: normal
status: open
title: re does not allow back references in {} matching operator
type: behavior
versions: Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20678>
_______________________________________
More information about the New-bugs-announce
mailing list