Rutwick Gangurde
Rutwick Gangurde

Reputation: 4912

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

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.

Upvotes: 1

Views: 168

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627082

You may use

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

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

enter image description here

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.

Upvotes: 1

Related Questions