Search/Replace of Multiline Text Blocs

  • Banned

    Axiomatic Ones:

    I use Notepad++ daily and I hold it in high regards. I recommend and refer Notepad++ to all visitors to my website. See:

    Edit Lottery data Files with Notepad++

    There is something I might be missing. There are situations when I edit my Web pages in bulk. For example, I add or remove scripts. They are multiline blocs of text. If the search/replace string is just one line, Notepad++ does a very good job. Except, it disregards the [End of Line] character.

    I would very much like to use Notepad++ to do the same good job with multiline blocs of text. I tried the Extended (\n, r, …) search option. There is NO documentation for that feature (or it is too well covered for my eyes!) I added \n at the end of each line in the bloc of text that I wanted to replace. It never worked for me.

    I am using a little freebie that works wonders for me: ‘Replace Text’ by Ecobyte. I use it to replace text in hundreds of Web pages at once. It has a special feature: ‘Advanced Edit’. I copy-and-paste blocs of text into ‘Advanced Edit’. It converts the bloc into a one-line string with special characters between the lines in the original bloc to be searched/replaced.

    Can I do the same thing in Notepad++? I would be much grateful.

    BTW –
    This post editor can be improved A LOT!

    Ion Saliu
    “A good man is an axiomatic man; an axiomatic man is a happy man. Be axiomatic!”

  • Hello, @ion-saliu,

    When the Extended search mode is selected, in one of four Search[-Replace] windows, any single character may be written, either, in the Find what: and the Replace With: zones :

    • With the decimal representation \d###, with 0 <= # <= 9 ( from \d000 to \d999 )

    • With the octal representation \o###, with 0 <= # <= 7 ( from \o000 to \o777 )

    • With the binary representation \b########, with 0 <= # <= 1 ( from \b00000000 to \b11111111 )

    • With the hexadecimal representation \x##, with 0 <= # <= 9 or a <= # <= f ( from \x00 to \xff )

    • With the Unicode representation \u####, with 0 <= # <= 9 or a <= # <= f ( from \u0000 to \uffff )

    In addition, the Tabulation, Antislash and Null characters may be represented by, respectively, the syntaxes \t, \\ and \0

    To end, the syntaxes \r and \n may be used and stand for the two End of Line characters Carriage Return and Line Feed

    Remarks :

    • So, the character, with the greatest Unicode code-point, which can be searched and or replaced, is :

      • The Unicode character ϧ ( COPTIC SMALL LETTER KHEI ), with code-point = \u03e7, in the decimal representation

      • The Unicode character ǿ ( LATIN SMALL LETTER O WITH STROKE AND ACUTE ), with code-point = \u01ff, in the octal representation

      • The Unicode character ÿ ( LATIN SMALL LETTER Y WITH DIAERESIS ), with code-point = \u00ff, in the binary or in the hexa representation

      • The Unicode character ( REPLACEMENT CHARACTER ), with code-point = \ufffd, in the Unicode representation

    • Note that the NULL character cannot be written, in the replacement zone, whatever its representation ( \0, \d000, \o000, \b00000000, \x00 or \u0000 )

    • I, strongly, advice you to check the Match case option and to uncheck the Match whole word only option

    • Of course, you may mix all these representations, either, in the Search and Replace zones !. For instance, the text \d065\o102\b01000011Z\x44\u0045 represents the simple string ABCZDE !!

    • Depending of the End of Line character(s), used in your current file, indicated in the status bar ( \r\n for a “Window” file, \n for an “Unix” file, and \r for a “Mac” file ), you can search and/or replace text, containing line break(s). For instance :

      • The search, with the Extended or Regular expression mode enabled, of the string ABC\r\n123 and the replacement by the string Word\r\nNumber, in a Windows file, would change the two lines :

    into the text :

      • This same S/R, in a Unix file, could be performed with the searched string ABC\n123 and the replaced string Word\nNumber

    Important :

    • The Search zone may contain between 1 and 2046 characters

    • The Replace zone may contain between 0 and 2046 characters

    So, for a Windows file, containing the original text :


    You could, perfectly, with the Extended or Regular expression mode set, use the following S/R :

    SEARCH Line_1\r\nLine_2\r\nLine_3\r\nLine_4\r\nLine_5\r\nLine_6\r\nLine_7\r\nLine_8\r\nLine_9\r\n

    REPLACE Modified Line #1\r\nModified Line #2\r\nModified Line #3\r\nModified Line #4\r\nModified Line #5\r\nModified Line #6\r\nModified Line #7\r\nModified Line #8\r\nModified Line #9\r\n

    to get the text :

    Modified Line #1
    Modified Line #2
    Modified Line #3
    Modified Line #4
    Modified Line #5
    Modified Line #6
    Modified Line #7
    Modified Line #8
    Modified Line #9

    But, the nice trick, with the search dialog, is that you DON’T need to separate the text of each line, with the End of Line characters \r\n :

    • Select, first, the original 9-lines text

    • Open the Replace dialog ( Ctrl + H )

    => The entire searched text is automatically filled

    Unfortunately, you CANNOT use this same work-around, for the replacement dialog -:(( So, you’ll still have to type all the text, below :

    Modified Line #1\r\nModified Line #2\r\nModified Line #3\r\nModified Line #4\r\nModified Line #5\r\nModified Line #6\r\nModified Line #7\r\nModified Line #8\r\nModified Line #9\r\n

    Best Regards,


    P. S. :

    Remember to not exceed 2046 characters for, both, the Search and the Replace zones ! Anyway, any surplus character is simply ignored

    For information, about the Extended search mode, see this article, in N++ Wiki :

    For information, about Regular expressions concept and syntax, begin with that article, in N++ Wiki :

    In addition, you’ll find good documentation, about the new Boost C++ Regex library, v1.55.0 ( similar to the PERL Regular Common Expressions, v1.48.0 ), used by Notepad++, since its 6.0 version, at the TWO addresses below :

    • The FIRST link explains the syntax, of regular expressions, in the SEARCH part

    • The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part

    You may, also, look for valuable informations, on the sites, below :

    Be aware that, as any documentation, it may contain some errors ! Anyway, if you detected one, that’s good news : you’re improving ;-))

  • Banned


    Thank you very much, indeed, axiomatic one. Really great information — a lot more than I would have ever expected. I copied-and-pasted your reply (including the links) for further reference.

    As I can see now, Notepad++ requires a lot of hard work. It didn’t work for me because copy-and-paste only pasted the first line! It is really cumbersome: Copy the bloc of text, start a new file, paste the multiline text, then go to the end of each line, delete the hidden [End Line] character, write \r\n, press [Delete] again, write again \r\n, press [Delete] again, …, sheesh…

    For now, I won’t use Notepad++ for such important tasks. The Ecobyte’s ‘Replace Text’ does such a marvelous job simply by copy-and-paste. It works flawlessly and it is fast.

    Google warned me recently that my site took a hit because of poor mobile usability. It turns out that the font size on my pages were too small for normal view on mobile devices (100% zoom). I had to increase the font size by 1pt. ‘Replace Text’ edited 1000+ html files in less than one minute! No errors whatsoever! It was even more useful when I needed to add several Google scripts on 1000+ Web pages in one step.

    That’s how I want to do this type of global replace in files (directly on disk). Notepad++ should add a Search (including in files) option named something like ‘Advanced Edit’. Just copy-and-paste should do. I am absolutely sure the gifted Notepad++ programmer can do it. I’m also sure he already took a look at Ecobyte’s ‘Replace Text’. I don’t think the algorithm is copyrighted: It is public domain or open source (as Scintilla).

    Ion Saliu
    “A good man is an axiomatic man; an axiomatic man is a happy man. Be axiomatic!”

  • Hi, @ion-saliu,

    Of course, I do understand your point of view and you, perfectly, spoke about the facility of that kind of S/R. So, you would like that this kind of feature, of Ecobyte’s Replace text, to be part of Notepad++ ? Well ! But do you know than an other guy requested for a very useful tool, seen in Sublime editor or that an other one really misses this other function, of Eclipse editor, and so on… !

    Although I’m always glad to see new N++ functionalities, in each next release and, that I long, as you, for some others, I just be satisfied with present Notepad++. I have not the C++ programming skills, yet, to develop N++ free product ( and I’ll probably never have ! ). This simple fact forces me to imagine some kind of work-around for non obvious N++ procedures ( for now ! ) !!

    After all, you should be happy to have found this other free software for your exact needs !

    Thinking about it, it’s just like if you wanted to see an animal, which could have all the qualities, partially belonging by each of the other animals ! Can you imagine, how boring it would be living, on earth, with that unique animal ? The spectacle of the life complexity seems much more gratifying ! Don’t you think so ?

    Finally, we just have the chance, nowadays, to, easily, get, on NET, the right software ( and, very often, a free one or a free version ! ), for any specific task that we want to achieve ;-)) And I bet, that some voluntary N++ programmers will notice, soon, a powerful feature, of an other coding editor, and, then, will work hard, trying to adapt it, in our beloved editor :-)) But, just realize that you can’t force them to get involved in your specific problems !

    However, I advice you to add a pull request, at the address, below :

    But, please, don’t expect a rapid reply to your request !!



  • I agree that line breaks should be handled by copy/paste to make the find and replace function vastly more useful. I managed to make use of guy038’s instructions to successfully replace a missing semicolon at the end of a single line in 73 files… but it wasn’t very intuitive and I had to go searching on the internet to find this answer.

    I confess to amusement at Ion Saliu’s predicament with increasing the font size in 1000+ html files. If you followed the W3C guidelines for correct html usage, the font size would be defined once in your stylesheet (ie CSS), and all your thousands of html files would render the font correctly without having to define it thousands of times.

  • @James-Faction said:

    but it wasn’t very intuitive

    So what are your ideas for making it more intuitive?

    line breaks should be handled by copy/paste to make the find and replace function vastly more useful

    What does this mean?

    We want to help but first we have to understand

Log in to reply