#!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())返回的字符串是自动的删除多余的空白了?


雷达卡



京公网安备 11010802022788号







