正则表达式检查句号后的空格数-严格要求2 [英] Regex to check number of spaces after full stop - Strictly 2 required

查看:125
本文介绍了正则表达式检查句号后的空格数-严格要求2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查在句号后放置一个空格的情况,然后将其替换为2个空格.我有正则表达式,但是Atom似乎调用无效.

I need to check occurrences where I have put one whitespace after a full-stop, and replace it by 2 spaces. I have the Regex for it, but Atom seems to call in invalid.

(?<=\.|\") {1,}(?=[a-zA-Z])

条件:

  1. 句点后1个空格.
  2. 如果句号以双引号引起来,则在引号后留1个空格.

上面的正则表达式非常适合我的情况,但是Atom无法对其进行验证.我需要将其用于现有文件.

The above regex works perfectly for my conditions however Atom is not able to validate it. I need to use it for existing files.

推荐答案

您可以使用

([."]) ([a-zA-Z])

,并替换为$1 $2.请参见 regex演示

and replace with $1 $2. See the regex demo and a regex graph:

详细信息

  • ([."])-组1(其值由替换模式中的$1反向引用引用):."
  • -一个空格(使用\s匹配任何空白)
  • ([a-zA-Z])-组2($2):ASCII字母.
  • ([."]) - Group 1 (its value is referred to with $1 backreference from the replacement pattern): . or "
  • - a space (use \s to match any whitespace)
  • ([a-zA-Z]) - Group 2 ($2): an ASCII letter.

这篇关于正则表达式检查句号后的空格数-严格要求2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆