How to search for multiple newlines?

Jep Z11
2013-11-09
2013-11-10
  • Jep Z11

    Jep Z11 - 2013-11-09

    Tried to find the answer and seen there's lots on the subject of newlines, yet I can not find the answer to this simple question.
    In other editors, \n\n will find two lines but not in NP++. Nor does \n\r find anything, so, what should I use?
    Plz, just an answer to this question, not some redirect as I am dizzy on how much there is on this subject. Thanks!

     
  • THEVENOT Guy

    THEVENOT Guy - 2013-11-09

    Hello Jep Z11,

    I don't need to redirect you, at all !

    Indeed, your two search regex ( \n\n or \n\r ) coudn't find any EOL, if your file has a Windows format, because :

    • In a file, with a Windows format, an End of Line is represented by the two characters \r\n ( \x0d\x0a )

    • In a file, with an UNIX/OSX format, an End of Line is represented by the unique character \n ( \x0a )

    • In a file, with an Old Mac format, an End of Line is represented by the unique character \r ( \x0d )

    ( Remenber that you can change this format of EOL in menu Edit\EOL Conversion of Notepad++ )

    Moreover, the special syntax \R can search any kind of EOL. Quite nice :-)

    And, as the symbol ^ represents the very beginning of a line :

    • A single blank line, in any format, can be matched with the regex ^\R

    • A list of consecutive blank lines, in any format, can be matched with the regex ^\R+

    So, if you wish :

    • To delete any blank line of a file, use the simple Search/Replacement below :

    SEARCH : ^\R

    REPLACE : Leave EMPTY

    • To delete any surplus blank line of a file, use the simple Search/Replacement below :

    SEARCH : ^(\R)+

    REPLACE : \1

    As the form \R is enclosed in round brakets, it represents the group 1, which is re-written, in the replacement part, as a single \r\n, or \n or \r, according the the file's EOL format !

    That's all !

    ( Tested with Notepad++ version 6.5.1 )

    Cheers,

    guy038

     
    Last edit: THEVENOT Guy 2013-11-09
  • Jep Z11

    Jep Z11 - 2013-11-10

    Thank you 'thevenot' for this clear, elaborate answer. Can see why there is so much ado on this as it requires a bit more than the average editor does. (yes, 'average'is a brand :) )
    It could be better explained in the help, I couldn't find it.

    NP++ is nice to me though for its features on css and html editing, so I guess I'll be a new user.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks