Pyparsing: Non-greedy matching?

Peter Fein pfein at
Fri Dec 31 04:22:07 CET 2004

On 12/31/04 03:00 AM CST, "Paul McGuire" <ptmcg at>
> Assuming that your <td> tag wont contain any nested <td> tag, you
> could define your data content as "everything up until I find
> '</td>'".  For this you can use pyparsing's SkipTo element.  I think
> if you define data as:
>     data = SkipTo("</td>")
> then your code should start working better.

Hey!  It does! ;) I just worked up (note to googlers- don't do this):
goodchars=printables.replace("<", "")
good_ab="<" + (~Literal(r"""/td>""") + SkipTo(">", include=True))
complex=Combine(simple | good_ab, adjacent=False, joinString="")
data=Combine(OneOrMore(complex), adjacent=False, joinString=" ")

But that would break for closers with more than one ">".  Need to stop
thinking like these are regexps.  Thanks - this is a great tool. ;)

Peter Fein                 pfein at                 773-575-0694

Basically, if you're not a utopianist, you're a schmuck. -J. Feldman

More information about the Python-list mailing list