Message211551
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. |
|
Date |
User |
Action |
Args |
2014-02-18 20:43:28 | hardkrash | set | recipients:
+ hardkrash, ezio.melotti, mrabarnett |
2014-02-18 20:43:28 | hardkrash | set | messageid: <1392756208.32.0.772076498816.issue20678@psf.upfronthosting.co.za> |
2014-02-18 20:43:28 | hardkrash | link | issue20678 messages |
2014-02-18 20:43:27 | hardkrash | create | |
|