Next / Previous / Contents / Shipman's homepage

5.31. StringStart: Match the start of the text

pp.StringStart()

An instance of this class matches only if the text position is at the start of the string.

>>> number = pp.Word(pp.nums)
>>> name = pp.Word(pp.alphas)
>>> pat1 = number + name
>>> print pat1.parseString('   7brothers')
['7', 'brothers']
>>> startName = pp.StringStart() + name
>>> pat2 = number + startName
>>> print pat2.parseString('   7brothers')
pyparsing.ParseException: Expected start of text (at char 4), (line:1,
col:5)