Newby: How do I strip HTML tags?
netvegetable
deathtospam43423 at altavista.com
Fri Jun 7 11:17:35 EDT 2002
I'm mucking around with cgi, and I'm trying to work out a way to strip the
html tags of a string. e.g, I want to convert this...
><font size = 12><b><big>Really Big String</big></b></font>
to this this ...
>Really Big String
... and store it as a value.
I worked out a crude, but effective way of doing it (see code below), but I
can't escape the feeling there must be a built in way of doing it more. If
nothing else, I'm sure somebody who knows their regular expressions could
neaten it up (please?).
def strip_html_tags(it):
left = it[:(len(it)/2)]
right = it[(len(it)/2):]
final = left[left.rfind('>')+1:] + right[:right.find('<')]
return final
--
netvegetable at excite.com
More information about the Python-list
mailing list