Notepad++
-
Hi.
I have the data as below:2433 George has a pillow.
**nothing new
**all the bad news
What is happening.
13984 good to know
Adam knows everything
**not in a good way
12 | new to Columbia
**im in a moodI have to merge the line beginning with space with the following lines that do not begin with spaces.
Expected result: (in 3 lines)
2433 George has a pillow.nothing newall the bad newsWhat is happening.
13984 good to knowAdam knows everythingnot in a good way
12 | new to Columbiaim in a moodCan anyone please help me how to execute this in Notepad++
-
@ravivarma-kv said in Notepad++:
I have to merge the line beginning with space with the following lines that do not begin with spaces.
This is a quick solution, however not entrely elegant as it will need running multiple times until no more changes occur.
It works on the premise that we look for a line with a space at the start, then if the following line does not have a space at the start it will merge both lines. By repeatedly running it it will grow the line with a space at the front by appending a “non-space” line at the rear.
Hopefully you know how regexes work. So under the Replace Menu.
Find What:^(\s.+)\R(^[^ ])
Replace With:\1\2
Set search mode as “regular expression” and Wrap around ticked. Click on the “Replace All”, do this multiple time until the Replace function returns “0 occurances were replaced”.Terry
-
Hello, @ravivarma-kv, @terry-r and All,
I found out a simple regex, which needs to be executed
one
time, only ! I just assume, as Terry did, that pure blank lines are deleted, as well !So, given, for instance, this sample text below :
1st line with 1 LEADING space This is a text which does NOT have any LEADING space 2nd line with 1 LEADING space A single line WITHOUT leading space 3rd line with 1 LEADING space 2nd multi-lines text with NO Leading space 4th line with 1 LEADING space 1st line with 3 LEADING space 5th line with 1 LEADING space 6th line with 1 LEADING space 3rd multi-lines text WITHOUT any leading space A last line with 1 LEADING space This is a very long multi-lines text with NO leading space for all the lines !
Use the following regex S/R :
SEARCH
\R(?=(\x20|\z)|)
REPLACE
?1$0
Of course, select the
Regex expression
search mode. You should get the expected text :1st line with 1 LEADING spaceThis isa textwhich doesNOT have anyLEADING space 2nd line with 1 LEADING spaceA single line WITHOUT leading space 3rd line with 1 LEADING space2nd multi-lines textwith NOLeading space 4th line with 1 LEADING space 1st line with 3 LEADING space 5th line with 1 LEADING space 6th line with 1 LEADING space3rd multi-lines textWITHOUT anyleading space A last line with 1 LEADING spaceThis is avery longmulti-lines textwithNO leadingspacefor allthelines !
I verified that I got the same output, using Terry’s regex solution ;-))
Notes :
-
This regex searches for any kind of EOL characters, followed by, either :
-
A space character or the very end of file ( => Group
1
exists ) -
Any kind of character ( other standard char or EOL char, due the empty alternative
|)
-
-
Due to the conditional replacement syntax
?1$0
, this matched EOL character is rewritten ($0
= Whole match ) only if the group1
exists. In all the other cases, it is just deleted
Remark :
If you prefer that the joined lines are separated with a
space
character, we need to distinguish between the standard characters, other than aspace
char, beginning the subsequent lines and any other character. So, use, instead, the followed regex S/R :SEARCH
(?-s)\R(?=(\x20|\z)|(.)|)
REPLACE
(?1$0)(?2\x20)
This time, due to the
(?2\x20)
conditional replacement, the matched EOL char is replaced with a singlespace
characterAnd you’ll get the text :
1st line with 1 LEADING space This is a text which does NOT have any LEADING space 2nd line with 1 LEADING space A single line WITHOUT leading space 3rd line with 1 LEADING space 2nd multi-lines text with NO Leading space 4th line with 1 LEADING space 1st line with 3 LEADING space 5th line with 1 LEADING space 6th line with 1 LEADING space 3rd multi-lines text WITHOUT any leading space A last line with 1 LEADING space This is a very long multi-lines text with NO leading space for all the lines !
Best Regards,
guy038
-