htmllib question

John Hunter jdhunter at nitace.bsd.uchicago.edu
Mon May 21 08:57:01 EDT 2001


>>>>> "Greg" == Greg Jorgensen <greg at pdxperts.com> writes:

    Greg> This may be more simplistic that you want. Then again it may
    Greg> be a workable solution.

Actually this is (almost) perfect.  The only change is that the regexp
must be non-greedy.  Thanks!

John Hunter

#!/usr/local/bin/python
import re

f = open('Edit.html', 'r')
rgx = re.compile(r'(<pre>.*?</pre>)', re.DOTALL+re.IGNORECASE)
chunks = rgx.split(f.read())
f.close()

for chunk in chunks:
    if chunk[0:5].lower() == '<pre>':
        print "In Pre"
        print chunk
        print "Out of Pre"
    else:
        print "In Else"
        print chunk
        print "Out of Else"







More information about the Python-list mailing list