神剑山庄资源网 Design By www.hcban.com

在pdf转为文本的时候,经常会多出空格,影响数据观感,因此需要去掉文本中多余的空格,而文本中的英文之间的正常空格需要保留,输入输出如下:

input:我今天 赚了 10 个亿,老百姓very happy。

output:我今天赚了10个亿,老百姓very happy。

代码

def clean_space(text):
  """"
  处理多余的空格
  """
  match_regex = re.compile(u'[\u4e00-\u9fa5。\.,,::《》、\(\)()]{1} +(" +", " ", s)

import re 

s = "     info has been found (+/- 100 pages, and 4.5 mb of .pdf files) now i have to wait untill our team leader has processed it and learns html.     "
re.sub(" +", " ", s)

' '.join(s.split())

s = "     info has been found (+/- 100 pages, and 4.5 mb of .pdf files) now i have to wait untill our team leader has processed it and learns html.     "

s = ' '.join(s.split())
s

更多关于python使用正则表达式去除多余空格方法请查看下面的相关链接

标签:
python使用正则表达式去除中文多余空格,python使用正则表达式保留英文空格,python去除英文之间多余的空格

神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com

评论“python使用正则表达式去除中文文本多余空格,保留英文之间空格方法详解”

暂无python使用正则表达式去除中文文本多余空格,保留英文之间空格方法详解的评论...