Next / Previous / Contents / Shipman's homepage

7.19. restOfLine: Match the rest of the current line

The variable pp.restOfLine is a parser that matches zero or more characters up to, but not including, the next newline character (or the end of the string, whichever comes first).

>>> text = 'Wolverhampton 3\nBristol nought\n'
>>> print pp.restOfLine.parseString(text)
['Wolverhampton 3']

To match the rest of the line including the newline character at the end (if there is one), combine this with the parser described in Section 7.12, “lineEnd: An instance of LineEnd.

>>> toNextLine = pp.Combine(pp.restOfLine + pp.lineEnd)
>>> print toNextLine.parseString(text)
['Wolverhampton 3\n']