new lines in replace?
-
So, I need to replace text. In “Find what”, it handles new lines in between characters/text just fine. However, the “replace with” field doesn’t recognize new lines from pasting. It simply cuts off all content after the new line/linebreak.
-
Use Extended for the Search mode and then use
\r\nin the Replace with text where you want the “new line/linebreak” to occur. -
Hello, @kracovwolf, @alan-kilborn and All,
The solution, provided by @alan-kilborn which uses the
Extendedsearch mode is really valuable !In fact, except in very rare cases, the syntaxes of the replacement part :
Line1\r\nLine 2\r\nLine3\r\nLine4\r\n...will preserved the syntax of each line !BTW, if you’re usually deal with
UNIXfiles ( see on the right part of the status bar ), you’ll have to change the REPLACE part as below :Line1\nLine 2\nLine3\nLine4\n...
For example, from this INPUT text :
ab$cD^E\Fg-h()iIJ[]K:L-
Open the Replace dialog (
Ctrl + H) -
Unckeck all box options
-
SEARCH
ab$cD^E\Fg-h()iIJ[]K:L -
REPLACE
ab$c\r\nD^E\F\r\ng-h()i\r\nJ[]K:L -
Check the
Wrap aroundoption -
Select the
Extended ( \n, \r, \t, \0, \x...search mode -
Click on the
Replace Allbutton
=> You get the expected OUTPUT text :
ab$c D^E\F g-h()i J[]K:L
In these others posts, below, I imagined a way to insert a multi-lines text, using the
Regular expressionsearch mode :https://community.notepad-plus-plus.org/post/97866
https://community.notepad-plus-plus.org/post/97904
However, now I see that the
Extendedsearch mode or, even better, theNormalmode could drastically simplify the method when applied to a single file !
So, when you want to insert a multi-lines text, even in several locations, of the current file, just follow this method :
- Let’s suppose that this INPUT text, below, is the text to be inserted :
------------- Inserted Multi-lines Text --------------
First, paste the text to be inserted in a new tab
-
Select this multi-lines text without its last line-break ( so the line-break after the series of dashes )
-
Open the Replace dialog (
Ctrl + H)
=> The multi-lines text should be copied in the
Find what:zone- Now, let’s switch to this text, in an other tab, which is the main text :
bla blah ¤ bla blah <test>¤</test> blah bla Begin ¤ blah bla blah ¤ endNote that I use the
¤symbol as an insertion symbol !- Click on the
⮁symbol, of the replace dialog, in order to swap the Find what and Replace with zones
=> The multi-lines text has moved into the
Replace with :zone-
Insert a single
¤symbol in theFind what :zone -
Unchek all the box options
-
Check the
Wrap aroundoption -
Select the
Normalsearch mode ( No need to choose theExtendedmode ) -
Click on the
Replace Allbutton
=> The
¤should have been replaced by the multi-lines text in four locations and you get the following OUTPUT text :bla blah ------------- Inserted Multi-lines Text ------------- bla blah <test>------------- Inserted Multi-lines Text -------------</test> blah bla Begin ------------- Inserted Multi-lines Text ------------- blah bla blah ------------- Inserted Multi-lines Text ------------- endBest Regards,
guy038
-