python文本过滤
#encoding:UTF-8 import re
temp = "想做/ 兼_职/学生_/ 的 、加,我Q: 8 8. 8 8. !!?? 8 8 。8. 8。 8 有,惊,喜,哦"
temp = temp.decode("utf8")
string = re.sub("[\s+\.\!\/_,$%^*(+\"\']+|[+——!,。?、~@#¥%……&*()]+".decode("utf8"), "".decode("utf8"),temp)
print string # def is_chinese(uchar):
# """判断一个unicode是否是汉字"""
# if uchar >= u'\u4e00' and uchar<=u'\u9fa5':
# return True
# else:
# return False # def is_number(uchar):
# """判断一个unicode是否是数字"""
# if uchar >= u'\u0030' and uchar<=u'\u0039':
# return True
# else:
# return False # def is_alphabet(uchar):
# """判断一个unicode是否是英文字母"""
# if (uchar >= u'\u0041' and uchar<=u'\u005a') or (uchar >= u'\u0061' and uchar<=u'\u007a'):
# return True
# else:
# return False # def is_other(uchar):
# """判断是否非汉字,数字和英文字符"""
# if not (is_chinese(uchar) or is_number(uchar) or is_alphabet(uchar)):
# return True
# else:
# return False # def B2Q(uchar):
# """半角转全角"""
# inside_code=ord(uchar)
# if inside_code<0x0020 or inside_code>0x7e: #不是半角字符就返回原来的字符
# return uchar
# if inside_code==0x0020: #除了空格其他的全角半角的公式为:半角=全角-0xfee0
# inside_code=0x3000
# else:
# inside_code+=0xfee0
# return unichr(inside_code) # def Q2B(uchar):
# """全角转半角"""
# inside_code=ord(uchar)
# if inside_code==0x3000:
# inside_code=0x0020
# else:
# inside_code-=0xfee0
# if inside_code<0x0020 or inside_code>0x7e: #转完之后不是半角字符返回原来的字符
# return uchar
# return unichr(inside_code) # def stringQ2B(ustring):
# """把字符串全角转半角"""
# return "".join([Q2B(uchar) for uchar in ustring]) # def uniform(ustring):
# """格式化字符串,完成全角转半角,大写转小写的工作"""
# return stringQ2B(ustring).lower() # def string2List(ustring):
# """将ustring按照中文,字母,数字分开"""
# retList=[]
# utmp=[]
# for uchar in ustring:
# if is_other(uchar):
# if len(utmp)==0:
# continue
# else:
# retList.append("".join(utmp))
# utmp=[]
# else:
# utmp.append(uchar)
# if len(utmp)!=0:
# retList.append("".join(utmp))
# return retList # if __name__=="__main__":
# #test Q2B and B2Q
# for i in range(0x0020,0x007F):
# print Q2B(B2Q(unichr(i))),B2Q(unichr(i)) # #test uniform
# ustring=u'中国 人名a高频A'
# ustring=uniform(ustring)
# ret=string2List(ustring)
# raw_input()
python文本过滤的更多相关文章
- 【python cookbook】【字符串与文本】12.文本过滤和清理
问题:例如清除在web页面表单中填入了pýtĥöñis这样的文本 解决方法:str.translate()方法 s = 'p\xfdt\u0125\xf6\xf1\x0cis\tawesome\r\n ...
- 改写《python基础教程》中的一个例子
一.前言 初学python,看<python基础教程>,第20章实现了将文本转化成html的功能.由于本人之前有DIY一个markdown转html的算法,所以对这个例子有兴趣.可仔细一看 ...
- 产品经理学Python:参数传递方式
这是关于Python的第5篇文章,主要介绍下参数传递方式和如何设计自己的函数. (一) 本篇主要介绍2种参数传递方式. 位置参数 调用函数时,根据函数定义的参数位置来传递参数. def right_t ...
- python书籍推荐:Python Cookbook第三版中文
所属网站分类: 资源下载 > python电子书 作者:熊猫烧香 链接:http://www.pythonheidong.com/blog/article/44/ 来源:python黑洞网 内容 ...
- 值得Python小白学习的书 简单推荐几本吧
于我个人而言,我很喜欢Python,当然我也有很多的理由推荐你去学python.我只说两点.一是简单,二是写python薪资高.我觉得这俩理由就够了,对不对.买本书,装上pycharm,把书上面的例子 ...
- 【Python】统计个人新浪微博词频并给出相应的柱状图
Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...
- python学习笔记——提取网页中的信息正则表达式re
被用来检索\替换那些符合某个模式(规则)的文本,对于文本过滤或规则匹配,最强大的就是正则表达式,是python爬虫里必不可少的神兵利器. 1 正则表达式re基本规则 [0-9] 任意一个数字,等价\d ...
- 朴素贝叶斯文本分类实现 python cherry分类器
贝叶斯模型在机器学习以及人工智能中都有出现,cherry分类器使用了朴素贝叶斯模型算法,经过简单的优化,使用1000个训练数据就能得到97.5%的准确率.虽然现在主流的框架都带有朴素贝叶斯模型算法,大 ...
- Python入门:参数传递方式
这是关于Python的第5篇文章,主要介绍下参数传递方式和如何设计自己的函数. (一) 本篇主要介绍2种参数传递方式. 位置参数 调用函数时,根据函数定义的参数位置来传递参数. def right_t ...
随机推荐
- eclipse gradle插件(buildship)的安装和使用
一.下载gradle https://gradle.org/gradle-download/ 二.手动安装gradle插件 我选择的是buildship,经过实际使用,体验很好. 插件的下载地址是: ...
- 升级openssl环境至openssl-1.1.0c
升级openssl环境至openssl-1.1.0c1.查看源版本 [root@zj ~]# openssl version -aOpenSSL 1.0.1e-fips 11 Feb 2013 2.下 ...
- PS切图篇
一.PS界面设置 1.新建(ctrl+n) 初始化尺寸参数 预设:自定 宽度:1920px 高度:自设(如:2000px) 分辨率:72像素/英寸 颜色:RGB/8位 背景内容:透明 存储为预设 2. ...
- 【转】CSS:table-cell详解
table-cell这个家伙在国外的网站中偶有露头,天朝由于IE6.7这两个货泛滥成灾,难有发挥,那么,这个家伙到底能干些什么呢?先让我们来研究下table,那些年曾经使用的table布局为何如此辉煌 ...
- c++左值和右值
c++编程中如果出现把一个函数的返回值.强行转化后的对象 作为函数的参数传进去时,编译器会报错的情况.这时候就该注意了,你需要把该函数的参数类型前加上const修饰. 原因在于c++的左值和右值有所区 ...
- json日期转换
//调用 ChangeDateFormat(CreatTime) //json日期转换 function ChangeDateFormat(jsondate) { jsondate = jsondat ...
- mybatis-mysql操作存储过程
java代码: @RequestMapping(value = "/testProcedure", method = RequestMethod.GET) public @Resp ...
- opencv vs环境配置
1.新建环境变量 OPENCV = D:\Programss\opencv\build 2.%OPENCV%\x86\vc12\bin;加入Path环境变量 3.导入 VS属性表文件 cv2413.p ...
- SQL SERVER与SSIS 数据类型对应关系
- 从github拉取项目到myeclipse本地
1.首先拿到jacky-lulu分享的地址 https://github.com/jacky-lulu1/cxf_client 2.登录jacky-lulu账号,fork一份cxf_client到自己 ...