Python 字符串过滤

需求:

str1 = "

"""
"""

"

想把 这段字符串的标签全部都去掉,比如去掉 ,   ,   

.。只保留不带<>的内容,但是要保留

有什么好的办法吗?使用正则可以实现这个工作:

# coding:utf-8
import re newline
= """












      />




  • 公司:   href="http://s.weibo.com/user/&work=%E6%89%AC%E5%B7%9E%E6%8A%A5%E4%B8%9A%E9%9B%86%E5%9B%A2&from=inf&wvr=5&loc=infjob" target="_blank">
      扬州报业集团
    地区:江苏 ,扬州
"""

newline= newline.replace('
','!!!###') re_comment = re.compile('<[^>]*>') newlines = re_comment.sub('', newline) newlines = newlines.replace('!!!###','
').replace('

','
').replace('

','
')
print newlines

输出结果是:

C:\Python27\python.exe F:/squid_frame/ZYXT__weibo/test.py

公司:扬州报业集团
地区:江苏 ,扬州
Process finished with exit code 0

 

你可能感兴趣的:(Python 字符串过滤)