RE: [Pyparsing] help with catchall style token
Brought to you by:
ptmcg
From: Paul M. <pa...@al...> - 2006-04-27 19:25:09
|
Try using SkipTo, as in: StringStart() + Word(num,exact=2) + SkipTo(Word(num,exact=2)) + Word(num,exact=2) + StringEnd() Or in the spirit of DRY: twoDigits = Word(nums,exact=2) expr = StringStart() + twoDigits + SkipTo(twoDigits) + twoDigits + StringEnd() -- Paul > -----Original Message----- > From: pyp...@li... > [mailto:pyp...@li...] On > Behalf Of Carl Shimer > Sent: Thursday, April 27, 2006 12:05 PM > To: pyp...@li... > Subject: [Pyparsing] help with catchall style token > > Hi, > > I would like to do something like this with pyparsing: > > Sample regex: > > r'^\d{2}.*\d{2}$' > > this matches on two numbers, followed by whatever is in the > middle, and ends with two numbers. > > I have tried the following with pyparsing but I can't find a > workable solution: > > StringStart() + Word(num,exact=2) + Regex('.*') + > Word(num,exact=2) + StringEnd() > > this doesn't work as the Regex eats everything. > > another thing I tried was > > StringStart() + Word(num,exact=2) + Word(alphas+alphas8bit) + > Word(num,exact=2) + StringEnd() > > this sort of works but doesn't work for utf-8 encoded > characters that may be in the range below alphas. > > Is there a solution here? > > > > |