0

How do you replace a line ending with a non-whitespace followed by zero or more spaces, by the matched non-whitespace followed by exactly two spaces, leaving the newline character intact?

Searching for this:

(\S)(\h*)$ 

will match. Replace with this:

\1  (?# two spaces after the one)

will leave the newline intact so that's OK. I was hoping it would discard the second match (\h* matches all whitespace except newline), but it doesn't. It leaves the second match, and adds two spaces in front of it.

Edit: This is an example. For clarity, [cr] is newline (CR + LF in windows), [sp] denotes 1 space, [2sp] 2 spaces, etc.

eggs[cr]
bacon;[2sp][cr]
[cr]
sausage.[3sp][cr]

should become

eggs[2sp][cr]
bacon;[2sp][cr]
[cr]
sausage.[2sp][cr]

Use case is writing markdown in Notepad++. I usually forget the two spaces marking <\br> I want to fix that with a regex search/replace. I know markdown is OK with two or more spaces, but still, it'd be cleaner to have just two. Without any additional search/replace of triple-or-more spaces, preferably.

RolfBly
  • 3,612
  • 5
  • 32
  • 46

1 Answers1

1

I'd just do:

Find what: (?<=\S)\h*$
Replace with: (two spaces)

Toto
  • 89,455
  • 62
  • 89
  • 125