Pyparsing: Non-greedy matching?

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


On 12/31/04 03:00 AM CST, "Paul McGuire" <ptmcg at austin.rr._bogus_.com>
sayeth:
> 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))
good_ab.setDebug(True)
simple=Word(goodchars)
complex=Combine(simple | good_ab, adjacent=False, joinString="")
data=Combine(OneOrMore(complex), adjacent=False, joinString=" ")
title4=title_open+data

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 pobox.com                 773-575-0694

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



More information about the Python-list mailing list