楼主: lobster_future
1124 0

[问答] 正在写一个检查文本多余空格,感叹号和多余单词的程序 [推广有奖]

  • 1关注
  • 0粉丝

已卖:1份资源

本科生

84%

还不是VIP/贵宾

-

威望
0
论坛币
96 个
通用积分
0
学术水平
0 点
热心指数
1 点
信用等级
5 点
经验
803 点
帖子
131
精华
0
在线时间
24 小时
注册时间
2017-1-15
最后登录
2018-4-13

楼主
lobster_future 发表于 2017-6-7 08:53:59 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

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

二维码

扫码加我 拉你入群

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

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

关键词:感叹号 Sentence Checking COMPILE without 感叹号 程序 单词

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-30 16:13