regex - 使用正则表达式查找和替换 - 仅删除字母之间的双空格
问题描述
尝试在 Atom 编辑器(1.39.1 x64,uBuntu 18.04)中执行此操作,但假设这适用于使用正则表达式的其他文本编辑器。
假设我们有这个文本:
This text has some double-spaces. Lets try to remove them.
But not after a full-stop or if three or more spaces.
我们想更改为:
This text has some double-spaces. Lets try to remove them.
But not after a full-stop or if three or more spaces.
使用Regex
启用的 ( .*
) 查找,使用以下方法正确找到所有匹配项:[a-zA-Z] [a-zA-Z]
。但是Replace
行中执行逻辑的内容是:
1st letter, single space, 2nd letter?
解决方案
你可以用这个
([a-z])\s{2}([a-z])
并替换为$1 $2
如果您的编辑器支持环视,您可以使用
(?<=[a-z])\s{2}(?=[a-z])
替换为单个空格字符
注意:- 不要忘记使用i
标志来区分大小写或将字符类更改为[a-zA-Z]
推荐阅读
- typescript - Typescript Type Guards 和粗箭头函数
- python - Matplotlib 的 get_ticklabels 不适用于自定义字符串标签
- angular - 如何使用 Angular 6 中的发布请求下载大文件
- url - 安装 Drupal 的 URL
- angularjs - 为什么 Chrome DevTools 不显示对象的所有属性?
- javascript - 角度 4 - 以分钟为单位的可观察计时器
- sql-server - 在每一页上重复静态 Tablix
- java - Java如何增加数据库表中双精度的值
- javascript - 如何在 localStorage 中存储列表
- python-3.x - 使用 Python BeautifulSoup 4 逐步展开 HTML 标签复合结构的最佳方法?