Next / Previous / Contents / Shipman's homepage

5.15. LineEnd: Match end of line


An instance of this class matches if the current position is at the end of a line or the end of a string. If it matches at the end of a line, it returns a newline ('\n') in the result.

>>> anb = pp.Word(pp.alphas) + pp.LineEnd() + pp.Word(pp.alphas)
>>> print anb.parseString('a\nb', parseAll=True)
['a', '\n', 'b']
>>> an = name + pp.LineEnd()
>>> print an.parseString('Dibley\n')
['Dibley', '\n']

In the next example, note that the end of the string does match the pp.LineEnd(), but in this case no value is added to the result.

>>> print an.parseString('Basingstoke')

For more examples, see Section 7.12, “lineEnd: An instance of LineEnd.