Next / Previous / Contents / Shipman's homepage

5.21. OneOrMore: Repeat a pattern one or more times

pp.OneOrMore(parser)

An instance of this class matches one or more repetitions of the syntax described by the parser argument.

>>> name = pp.Word(pp.alphas)
>>> nameList = pp.OneOrMore(name)
>>> print nameList.parseString('You are in great peril', parseAll=True)
['You', 'are', 'in', 'great', 'peril']
>>> hiway = pp.Combine(pp.Word(pp.alphas) + pp.Word(pp.nums))
>>> hiwayList = pp.OneOrMore(hiway)
>>> print hiwayList.parseString("I25 US380 NM18", parseAll=True)
['I25', 'US380', 'NM18']