This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author hardkrash
Recipients ezio.melotti, hardkrash, mrabarnett
Date 2014-02-18.20:43:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1392756208.32.0.772076498816.issue20678@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-02-18 20:43:28hardkrashsetrecipients: + hardkrash, ezio.melotti, mrabarnett
2014-02-18 20:43:28hardkrashsetmessageid: <1392756208.32.0.772076498816.issue20678@psf.upfronthosting.co.za>
2014-02-18 20:43:28hardkrashlinkissue20678 messages
2014-02-18 20:43:27hardkrashcreate