0

I want to transform this

a

b


b

into this

a
b
b

number of empty lines is variable and can be pretty huge. Empty lines contains spaces. I want to use a regexp like \r\n( *\r\n)+, but notepad++ seems not to like those special characters in regexp, tryed also \\r\\n( *\\r\\n)+

Please note that empty lines may contain spaces, so the correct regexp would be something like \\r\\n( *\\r\\n)+

Paolo
  • 2,461
  • 5
  • 31
  • 45
  • I don't know about Notepad++, but Usually `$` represents a beginning of line and `^` represents an end of line... – Ilya Kogan Dec 07 '11 at 09:25
  • possible duplicate of [Finding and replacing blank lines regex in Notepad++](http://stackoverflow.com/questions/5381444/finding-and-replacing-blank-lines-regex-in-notepad) – stema Dec 07 '11 at 09:27
  • 2
    Ilya, it's the other way round. – Joey Dec 07 '11 at 09:27
  • This is not directly possible with regex in Notepad, because the regexes are limited to only one row (newlines are removed by the regex engine), but you can see my [answer here](http://stackoverflow.com/a/5381649/626273) or of course the other answers to that question. – stema Dec 07 '11 at 09:29
  • @stema very close to the other question, but I have also spaces and other question has no regexp answer too. – Paolo Dec 07 '11 at 09:31
  • 1
    @Paolo: You should have mentioned in your original question that there are spaces in those blank lines. – BoltClock Dec 07 '11 at 09:31
  • @Paolo, there is no pure single regex answer to this question for Notepad++ – stema Dec 07 '11 at 09:34
  • @BoltClock I did, as long I realized it was relevant I mentioned it. – Paolo Dec 07 '11 at 09:34

1 Answers1

4

You can do 'replace all' multiple times on

\r\n\r\n -> \r\n

That's with 'Extended' option selected, not 'Regular expression'.

If the empty line contains spaces, then first replace all lines with only spaces with nothing using regex: ^\s+$ -> ''. Then to the extended replacement above.

Alternatively:

You can also replace all \r\n with some sequence of characters that doesn't exists in the document, e.g. ### then use the following regex replacement : '###(\s*###)+' -> '###' and finally replace back the sequence ('###') with \r\n.

Petar Ivanov
  • 91,536
  • 11
  • 82
  • 95