Regex to check number of spaces after full stop - Strictly 2 required

半世苍凉 提交于 2019-12-11 13:41:51

问题


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])

Conditions:

  1. 1 spaces after period.
  2. If period in with a closing double quote, then 1 space after the quote.

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


回答1:


You may use

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

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

Details

  • ([."]) - 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.


来源:https://stackoverflow.com/questions/56323075/regex-to-check-number-of-spaces-after-full-stop-strictly-2-required

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!