I'm in a Paragraph Find and Replace Hell
-
Fellow Notepad++ Users,
Could you please help me the the following search-and-replace problem I am having?
Im trying to turn the following text into the text mentioned after that. But instead of turning the 5 line text (first one) into the 3 line text (second one), it turns it into a 2 line text.
Here is the data I currently have (“before” data):
‘Colt?’ He turns to face her, and clears his throat. Guilty sign. Very guilty. Probably has a guilty look on his face, but you can’t tell, because he’s still wearing that helmet so you can’t see his eyes.Here is how I would like that data to look (“after” data):
‘Colt?’ He turns to face her, and clears his throat. Guilty sign. Very guilty. Probably has a guilty look on his face, but you can’t tell, because he’s still wearing that helmet so you can’t see his eyes.The “2 line text”:
‘Colt?’ He turns to face her, and clears his throat. Guilty sign. Very guilty. Probably has a guilty look on his face, but you can’t tell, because he’s still wearing that helmet so you can’t see his eyes.To accomplish this, I have tried using the following Find/Replace expressions and settings
- Find What =
(?<![\.\!\?])\r\n([a-z]) - Replace With =
\1 - Search Mode = REGULAR EXPRESSION
- Dot Matches Newline = NOT CHECKED
Unfortunately, this did not produce the output I desired, and I’m not sure why. Could you please help me understand what went wrong and help me find the solution?
- Find What =
-
Hello @offshore9521 and All,
Humm…, @offshore9521, there are two separate problems with your regex !
From your INPUT text :
‘Colt?’ He turns to face her, and clears his throat. Guilty sign. Very guilty. Probably has a guilty look on his face, but you can’t tell, because he’s still wearing that helmet so you can’t see his eyes.Your regex
(?<![\.\!\?])\r\n([a-z])means :-
If a
\r\nsequence, followed with a letter (a through z), is not preceded by :-
A dot
-
An exclamation mark
-
An interrogation mark
-
-
Then rewrite this letter
BTW, you can shorter this regex as
(?<![.!?])\r\n([a-z])But, the
’character is not a character of the[.!?]list. Thus, this explains why your regex merges the lines1and2
Now, I suppose that your true goal was : if a line is not a true sentence, then merge that line with the next one with a space character ? This lead to the follwing regex S/R :
FIND
(?<![.!?’])\r\n(?=\w)REPLACE
\x20So, any
\r\nsequence is simply replaced with a space character
Notes :
-
As you see, I included the
’character within the list of the forbidden chars, in the negative look-behind -
I used
\w, which is identical to the[\u\l\d_]class character, instead of[a-z]to not bother about case !
Remark :
- Instead of
\r\n, I could have used the\Rsyntax with matches any kind of line endings (\r,\nor\r\n), but, because it is preceded by a negative look-behind, we must insert\rand\nas forbidden characters, as well !
FIND
(?<![.!?’\r\n])\R(?=\w)REPLACE
\x20Best Regards,
guy038
P.S. : As an exercice, try to understand why the following regex S/R does not work as expected :
FIND
(?<![.!?’])\R(?=\w)REPLACE
\x20To help you, don’t forget to click on the
¶icon of the Toolbar ! -