python - 正则表达式:如何在 python 中使用 re.sub() 将两个完全匹配组合成一个?
问题描述
解决方案
根据您的回答,我相信这是您正在寻找的答案:
import re
text = '“Client” refers to Client or “”any User uploads or otherwise supplies to, or stores in, the Services under Client’s account.'
re.sub(r'[^\w|^\d|^\s]+', '', text)
输出:
'Client refers to Client or any User uploads or otherwise supplies to or stores in the Services under Clients account'
替换所有字符,除了:
^\w
单词字符,例如 AZ 和 az^\d
数字^\s
空白
考虑到您的特殊字符列表的广度,这种排他过滤比包容过滤更有效。
推荐阅读
- python - 如何检测网站上的变化?python网页抓取
- javascript - 我想制作一个 2d 汽车动画,例如使用滚轮前进和后退的爬山赛车。我正在使用 javascript、html 和 css
- sql - 查询帮助:过去 15 天的运行平均值
- typescript - 使用递归类型别名会产生循环引用错误
- python - 如何使我的 PySimpleGui 窗口使用不那么单一?
- email - Plesk 正确发送电子邮件但无法接收外部电子邮件
- python - 带有python超时的whatsApp-web驱动程序
- reactjs - 反应:接受通用接口作为道具
- javascript - 使用 hyperswarm 库在连接的服务器之间复制消息
- javascript - 需要帮助弄清楚如何根据用户输入数字显示新的网格尺寸