need help with re module

Matimus mccredie at gmail.com
Wed Jun 20 22:27:03 CEST 2007


Here is an example:

>>> s = "<html>Hello</a>world<anytag>ok"
>>> matchtags = re.compile(r"<[^>]+>")
>>> matchtags.findall(s)
['<html>', '</a>', '<anytag>']
>>> matchtags.sub('',s)
'Helloworldok'

I probably shouldn't have shown you that. It may not work for all
HTML, and you should probably be looking at something like
BeautifulSoup.

Matt




More information about the Python-list mailing list