全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 python论坛
1123 0
2017-06-07
#!python3
# 7typeErrorRegex - to find the error in the text (include too many spaces after the word, repeat word and too many ! in the end of the sentence)
import re,pyperclip
#copy the text
text=str(pyperclip.paste())

#create space regex
spaceRegex=re.compile(r'(\w*\s)(\s){1,}')
if len(spaceRegex.findall(text))>0:
    print('Here is the text without the space error: ')
    print(spaceRegex.sub(r'\1',text))
else:
    print('There is no space error in the text')
text1=spaceRegex.sub(r'\1',text)

#delete the repeat word in the text
i=re.compile(r'(\w+)\1+')
if len(i.findall(text))>0:
    print('Here is the text after the checking: ')
    print(i.sub(r'\1',text1))
else:
    print('there is no such error of repeat word occuring in the text')
text2=i.sub(r'\1',text1)
#delete too many ! after the sentence
j=re.compile(r'(!){1,}')
if len(j.findall(text))>0:
    print('Here is the text without the repeat ! error: ')
    print(j.sub(r'!',text2))
else:
    print('There is no ! error in the text')
text3=j.sub(r'!',text2)
运行检查重复感叹号和单词的时候没有问题,但是运行检查多余空格时不管输入的text里面是有多少重复空格,都会返回说没有找到空格处,并且返回的文本是去除了空格的。在交互界面输入这些也可以成功返回没有空格的字符串,说明这样的程序应该没有问题,求解答是不是因为text=str(pyperclip.paste())返回的字符串是自动的删除多余的空白了?

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群