Re: [Pyparsing] multiple tokens but no repeats
Brought to you by:
ptmcg
From: Ralph C. <ra...@in...> - 2007-11-20 17:10:24
|
Hi Tim, > I'm trying to represent the logic that I wish to match 0 or more > tokens, up to a maximum of 4 tokens, but I don't want any repeats of > tokens already matched within the group of 4. How could I do that? I'm not sure if you can. Perhaps there's a way to run your own validation code as each attempt to grow the number of matches occurs? Otherwise, since there's only four I'd enumerate the alternatives, e.g. a ab ac ad abc abd acb acd adb adc abcd abdc acbd acdb adbc adcb If I've got that right, there's 16 alternatives starting with `a'. The other three follow a similar pattern making 64 in total. You could factor out the common prefixes to speed up a Regex() a bit if you find that just a dumb list seems slow. Be sure to check whether order determines whether it matches the longest possible, e.g. `abcz' should match `abc' and not `a' or `ab'. Cheers, Ralph. |