python正则如何去除字符串
比方说我有一段文本,s="<div>test</div><img src='aaa.jpg'><a href=#>test</a><span>www.csdn.net</span><table>someother</table>",我想去除除<img>标签和<a>标签以外的所有标签,即经过处理后得到的字符串应该是"test<img src='aaa.jpg'><a href=#>test</a>www.csdn.netsomeother",python的正则感觉好别扭,求大神指教
[解决办法]
import redef repl(m): if m.group(1).strip() in ('cat', 'dog'): return '' return m.group(0) s = 'this <cat>is<dog> a test<pig>'print re.sub(r'<(.*?)>', repl, s)