Regular Expression: How to search for NEWLINE

FlakRat
2006-01-18
2012-11-13
  • FlakRat

    FlakRat - 2006-01-18

    Howdy, I ran into a situation where I needed find lines with a specific pattern and remove the line entirely.

    In Textpad, I would use:
    Find: ^\t\t[0-9].*$\n
    Replace:

    With the replace string empty, the entire line is removed.

    I can't find a way to specify the newline character or carriage return or form feed etc...

    Can you do this in Notepad++?

     
    • Philip Nicolcev

      Philip Nicolcev - 2008-03-27

      I have to agree with the above. Even just as a web developer I find I need to do searches with regular expressions and \n that are just not well supported in n++. The TextFX find/replace is what I use for this, however there appear to be times when it just doesn't find things that are present when I search for multiple lines.

       
    • Nobody/Anonymous

      The problem depends on Scintilla. It does not support search/replace linefeed newline character or carriage return in Regular Expressions.

      My be, that this problem could be solved with a workaround.

      Regards
      Jens

       
      • bushost_teamleader

        There is a text editor which is not as clean as N++ but one thing I like about it better than N++ is the regular expression support.  Due to the fact that it uses the PCRE 5.0 library, it has vastly superior regular expression support.  It is the one feature of N++ I would like to see changed.  As much as I love N++, its lack of full regex support leaves me either trying workarounds or using boxer, which I feel is not as clean as N++.  It would be great if N++ could use PCRE instead.

         
        • Nobody/Anonymous

          It should be mentioned in the FAQ that the regular expression engine does not support \n

           
          • Nobody/Anonymous

            Theres a lot of regular expression features Notepad++ doesn't support that should have been mentioned in the FAQs. I'm just getting familiar with reg expressions and I've just spend hours trying to figure out how to use functions that aren't available. It's pretty frustrating, and too bad since I was starting to like using this application.

             
            • Miguel Melo

              Miguel Melo - 2007-04-06

              I just started playing around with Notepad++, it's a remarkable editor. But in my line of coding work I use regexps every day and I find this to be N++'s biggest limitation so far - meaning I'll probably stick to PSPad. Not having something as simple as \w or \s is just extremely limiting: I haven't tried any positive/negative lookaheads/lookbehinds but since there's no support for the basic tokens about I don't expect these more advanced features will be there... :(

               
              • Nobody/Anonymous

                Hello,

                I also had a problem with the \n characters - for me the solution was to install  Simple script plugin; then there one can write a script in the format

                replace("\n\n", "\n")

                and apply the replacement to the selected text, which is what I need (I map one script to a shortcut, and then change the script statement as needed). I haven't tried more complicated regex but I don't think regex as such is directly supported in Simple Script plugin.

                However, I also think that it uses the same search/replace engine as rest of Notepad++, and it's a shame that I cannot access "\n" escaped characters from the Find dialog. I believe that a very quick fix (without implementing a separate regex engine) would be to include something like a checkbox "Transform (interpret) backslash characters" on the Find dialog, just as in Notepad2 I believe - so usage of \n would be thus supported; although maybe not in the sense of being mixed with a regex; so I would like to suggest that for a future version :)

                 
    • Chris Severance

      Chris Severance - 2006-01-19

      Due to Scintilla's limitations, I'd do this in two steps. The first step turns a regex find into a non regex find which can then be replaced multiline. I'd first replace the text with special text that isn't found elsewhere in the document.

      RegEx Enabled, easiest in Ctrl+R dialog
      Find ^TABTAB[0-9].*$
      Replace XYZZY

      Then let a non regex multiline search destroy the rest.

      Find XYZZYRETURN
      Replace

      It's not a great solution but it's all we have.

       
    • Nobody/Anonymous

      Thanks y'all, not the most straight forward technique, but it works :-)

       
    • Nobody/Anonymous

      I agree completely!! N++ is the best thing since sliced bread, and it's only downfall is lack of full regex support. This change would make it the best thing out there.

       
    • Nobody/Anonymous

      I too would like to see full regex support.

      It's interesting (and deceiving) that when doing a replace, the replace can be \n, just not the find.

       
    • Nobody/Anonymous

      full regex support is needed, this is thrue.

      Vote 1+

      Thanks

       
    • Nobody/Anonymous

      I agree 100%. I downloaded this program because I was hoping it would have this feature specifically. Should change it to support full regex, but in the meantime you should definitely add a note to the FAQ to let people know that newline searches aren't possible yet.

       
    • Nobody/Anonymous

      Yes, full regex all the way.
      Some better docs would be good - not on regex in general but highlight any Notepad++ specifics. I too went on a search for newlines and failed :-(

       
    • Nobody/Anonymous

      Actually, I search and replace new lines all the time with Notepad++ - you just need to use the Find/Replace that is part of the TextFX plugin. Use Ctrl-R to open it. You can then copy a NL/CR from the document, paste it into the search and/or replace box, and run.

       
    • Naoto

      Naoto - 2006-08-26

      Oh, I got it. Thank you.
      At first I did not get what above message was saying. But now I can do it. Just type text and hit Enter key to include CF/LR. Those symbles do not show in dialog, but with new line. I mean 2nd line.

       
    • Nobody/Anonymous

      Steps to replace all EOLs with some arbitrary string (including a string of length 0)
      1) CRTL-R (instantiates the TextFX Find/Replace dialog)
      2) UN-check the RegEx checkbox
      3) Click in the find field
      4) CTRL-M or CTRL-ENTER (this inserts the EOL character into the find field)
      5) type the string to replace with in the replace field
      6) Use the Find, Repl%Find Again, or Replace buttons as desired

       
      • pshute

        pshute - 2007-04-19

        All the tricks I could discover for working with newlines in Search and Replace are described at http://notepad-plus.sourceforge.net/uk/newlineFindReplace-HOWTO.php .  I didn't know you could type control+Enter instead of control+M.

         
    • Nobody/Anonymous

      Yes!  This does work!  Thanks so much for describing it so well.

      Tom Haws

       

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

Sign up for the SourceForge newsletter:





No, thanks