How do I remove single line breaks?

2019-08-14 12:10发布

问题:

I want to remove single line breaks in my text but not double ones.

I'm able to replace lines using \r\n. How can I remove single line breaks?

EDIT: I also need to add space before each line. For example if original text is:

line1
line2
line3

it must be converted to:

line1 line2 line3

回答1:

If I've got your point - you need to convert single \r\n to space but leave double, triple and so on.

You can use replace function of Notepad++ and this regular expression

(?<!\r\n)\r\n(?!\r\n)

Here we have negative lookbehind of \r\n, then \r\n itself and then negative lookahead of \r\n, so it matches single occurence of \r\n having no predecessors and no successors of the same characters.

Something like:

Note: you have to check "Regular expression" radiobutton at the bottom of form. Also field "replace with" should contain single space character.

As a result it converts following text:

line1
line2
line3

line4
line5

into this one:

line1 line2 line3

line4 line5


回答2:

You can try to use CTRL + A and then CTRL + J