#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文本过滤的更多相关文章

  1. 【python cookbook】【字符串与文本】12.文本过滤和清理

    问题:例如清除在web页面表单中填入了pýtĥöñis这样的文本 解决方法:str.translate()方法 s = 'p\xfdt\u0125\xf6\xf1\x0cis\tawesome\r\n ...

  2. 改写《python基础教程》中的一个例子

    一.前言 初学python,看<python基础教程>,第20章实现了将文本转化成html的功能.由于本人之前有DIY一个markdown转html的算法,所以对这个例子有兴趣.可仔细一看 ...

  3. 产品经理学Python:参数传递方式

    这是关于Python的第5篇文章,主要介绍下参数传递方式和如何设计自己的函数. (一) 本篇主要介绍2种参数传递方式. 位置参数 调用函数时,根据函数定义的参数位置来传递参数. def right_t ...

  4. python书籍推荐:Python Cookbook第三版中文

    所属网站分类: 资源下载 > python电子书 作者:熊猫烧香 链接:http://www.pythonheidong.com/blog/article/44/ 来源:python黑洞网 内容 ...

  5. 值得Python小白学习的书 简单推荐几本吧

    于我个人而言,我很喜欢Python,当然我也有很多的理由推荐你去学python.我只说两点.一是简单,二是写python薪资高.我觉得这俩理由就够了,对不对.买本书,装上pycharm,把书上面的例子 ...

  6. 【Python】统计个人新浪微博词频并给出相应的柱状图

    Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...

  7. python学习笔记——提取网页中的信息正则表达式re

    被用来检索\替换那些符合某个模式(规则)的文本,对于文本过滤或规则匹配,最强大的就是正则表达式,是python爬虫里必不可少的神兵利器. 1 正则表达式re基本规则 [0-9] 任意一个数字,等价\d ...

  8. 朴素贝叶斯文本分类实现 python cherry分类器

    贝叶斯模型在机器学习以及人工智能中都有出现,cherry分类器使用了朴素贝叶斯模型算法,经过简单的优化,使用1000个训练数据就能得到97.5%的准确率.虽然现在主流的框架都带有朴素贝叶斯模型算法,大 ...

  9. Python入门:参数传递方式

    这是关于Python的第5篇文章,主要介绍下参数传递方式和如何设计自己的函数. (一) 本篇主要介绍2种参数传递方式. 位置参数 调用函数时,根据函数定义的参数位置来传递参数. def right_t ...

随机推荐

  1. 微信小程序-提示框

    提示框: wx.showToast(OBJECT) 显示消息提示框 OBJECT参数说明: 示例代码: wx.showToast({ title: '成功', icon: 'success', dur ...

  2. (转)Linux grep

    文章转自 http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856896.html 简介 grep (global search regular ...

  3. 通过nginx代理之后,获取客户端ip

    1.相关nginx配置(通过header将客户端ip,host等信息传入) location ~ .*.do$ { proxy_set_header X-Real-IP $remote_addr; p ...

  4. 在阿里云配置URL的REWRITE模式

    今天买了阿里云的虚拟主机,然后把我的项目上传. 网站首页能够访问,但是点开任何页面,都是提示No input file specified,猜测应该是URL重写没有生效,我在浏览器地址把index.p ...

  5. OpenCV 计算区域的内部参数

    对于一个区域,怎么进一步针对区域内部特征进行处理呢 ? 首先,我们要提取出来内部的某些特征才能说话,下面提取一些简单的特征,话不多说见代码: 1.平均数及方差参数: Mat tempMean, tem ...

  6. try-catch

    try{ // 程序代码 }catch(异常类型1 异常的变量名1){ // 程序代码 }catch(异常类型2 异常的变量名2){ // 程序代码 }catch(异常类型2 异常的变量名2){ // ...

  7. mysql 基础篇5(mysql语法---数据)

    6 增删改数据 -- ********一.增删改数据********* --- -- 1.1 增加数据 -- 插入所有字段.一定依次按顺序插入 INSERT INTO student VALUES(1 ...

  8. maven 使用

    1. download maven from http://maven.apache.org/ 2. unzip, setup MAVEN_HOME 3. change the configurati ...

  9. 前台jquery+ajax+json传值,后台处理完后返回json字符串,如何取里面的属性值?(不用springmvc注解)

    一.取属性值 前台页面: function select(id){ alert("hfdfhdfh"+id); $.ajax({ url:"selectByid.jsp& ...

  10. 利用node来下载图片到本地

      本文是针对于知道图片地址的下载图片方法. 同时也是我的处男作(额,怪怪的〜);不要在意这些细节. 最近在弄项目迁移,需要把http的链接全换成https的:以前的cms不支持http的协议,然后就 ...