Regular expressions: \n \t etc

  • ppmnt

    ppmnt - 2005-04-19

    How do I use new lines or tabs in regular expressions? For example: I'd like to replace all pipes (|) in a file with new lines, and then all colons (:) with tabs. This would turn this:

    First Name: Foo|Last Name: Bar


    First Name:     Foo
    Last Name:     Bar

    However, if I attempt to replace "|" with "\n" it literally inserts "\n", even with regex on. This is how I used to do the same thing with Textpad. Is this possible?

    • Josh Harris

      Josh Harris - 2005-08-27

      The search functions are done by the Scintilla component, which is a 3rd party editing component used by Notepad++ and for regexp, it searches one line at a time.  It grabs the text of the current line, excluding \r and \n characters so that it is why they are not searchable.  For non-regexp searches, it looks like it goes through the text character by character, which includes \r and \n.

      I am actually working on modifying Scintilla for myself so that it does search for \r and \n (and also adding a few other things, such as deleting a line that a match is found on.  And I also changed it's regexp library to use pcre because I didn't like the limitations of the normal regexp syntax that it used) but I am not really sure I plan on releasing it.  I've been using it for a week or so but it's not quite ready anyway.

      • Dave F

        Dave F - 2005-08-30

        i hope you do release it, i'd love multiline PCRE

    • ppmnt

      ppmnt - 2005-04-19

      I have to apologize. You guys are cool, and I was a typical luser. Of course I was using version 2.8, and when I upgraded to 2.9 the requested features worked fine. When in doubt, always upgrade first, eh? (And reboot if it's Windows)


    • Fábio Lutz

      Fábio Lutz - 2005-05-05

      Well, it seems like replacing some character by \t or \n works fine, but if i try to find any \n or \t to replace them for another char (like changing all line breaks by commas), i cant do this because N++ just dont find them.

      Is there another version that fix this problem ?

      • Don HO

        Don HO - 2005-05-10

        You can find and replace "\t" when the regular expression is checked.
        However, you can not find and replace "\n".
        Unfortunately I don't have the solution for the moment.


        • Nobody/Anonymous

          Does this mean the regexp search is limited to a single line? Seems so to me..
          However, without regexp on, you can make a multi-line selection, press Ctrl-f and it will use the selection as search mask - this works.


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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks