Menu

Finding several New Lines with RegExp

2007-11-27
2012-11-13
  • Raúl Mateos

    Raúl Mateos - 2007-11-27

    Hi!

    I'm trying to do something that I don't know if it's posible:

    I'm parsing cpinfo FW-1 file. I look for this text:

    ==============================================
    CP components
    ==============================================

    Is it posible to find with regexp every text like that:

    [several=][New Line]
    [TEXT][New Line]
    [several=][New Line]?

    I have used regexp like (I know it looks strange, just the concept): "[=]+$[a-Z, ]$[=]+$"

    but no luck. Any idea? Is it posible?

    Thanks.
    Raul

     
    • Nobody/Anonymous

      If you would check some former messages, you would find a link that may help you.

      You might find the following explanation there:

      The $ symbol will match newlines, but they won't be replaced by the replace string. They only help locate the position of it - you can only use them at the end of the search string, because this command only searches within lines in this mode.

       
    • pshute

      pshute - 2007-12-02

      I don't think it can be done with regex in Notepad++.  If you use the advanced find/replace without regex, you can use control+M to represent newlines in either the find or replace string.  See http://notepad-plus.wiki.sourceforge.net/FindReplaceNewlineHowTo for details.  I'm not sure if this solves your problem, but it should at least explain what can be done.

       
      • Hughie

        Hughie - 2007-12-04

        I have a similar problem; I am trying to remove all "blank" lines from a file.

        So using the advanced find/replace dialogue, in the "Find" box I entered CTRL-M twice and in the "Replace" box I entered one CTRL-M.  As far as I can tell, this should work.  But the "Repl&FAgain" and "Replace Rest" buttons are greyed out.  So I am only able to "Find" and "Count" how many instances of a double CRLF occur, but I am not able to replace them with a single CRLF.  Am I missing something?

         
        • Nobody/Anonymous

          Yes, you have to press the Find button first, before you can be allowed to Replace an entry...

          However, you would have to check Recurse Repl. in order to also compress multiple blank lines. Normally a double EOL would be replace by one and the next couple of EOL would be searched. Recurse Repl. starts again at the start of the replacement/insertion.

          There is yet an easier way:
          Select all text (CTRL+A)
          Select menu TextFX, option TextFX Edit, option Delete Blank Lines

           
          • pshute

            pshute - 2007-12-05

            > Yes, you have to press the Find button first, before you can be allowed to Replace an entry...

            You should also check that the lines don't have an invisible space or tab on them to cause them not to match.  Have you tried View/Show Whitespace?

             
    • Nobody/Anonymous

      One thing I found you can always do when you want to search/replace across multiple lines is to use the hex editor plugin to to temporarily change all the carriage-return + newlines to something else (a control character or something else not already in the file), then switch back to normal view to do your replace and then back to hex to put back the line ends.  Not sure if there is any file size or line length limitation on this.

       
      • Nobody/Anonymous

        Yes, there are a lot of ways to reach your destination while taking more time than necessary. Why would you do that?

         
        • Nobody/Anonymous

          > Yes, there are a lot of ways to reach your destination while taking more time than necessary. Why would you do that?

          So what was the/your advice here that you must think I inadvertently brushed off?  Sensitive nobody.

          You might want to reread or firstread the thread before you post.

          What I had to do today was to remove many newlines which were actually in the middle of lines (lines end with carriage-return + newline).  The best way I know of to do that (in this editor) is to do it with a hex search and replace. It's too easy.  But if there's a slicker way, you can help out.  I've also done search and replaces (in notepad++) across multiple lines and doing it as I outlined (temporarily get rid of the end-of-lines) has worked well.  If there's a general purpose slicker way, then put up.

           
          • pshute

            pshute - 2007-12-11

            > What I had to do today was to remove many newlines which were actually in the middle of lines (lines end with carriage-return + newline)

            Another tool we have for working with these is Format/Convert to Unix or Windows or Mac.  This converts CR/LF pairs to/from CR or LF singles, etc.  I suspect in your case it might make things worse, as you won't know where the real ends of lines are anymore.

            Also, I've been using the term "newline" to mean whatever kind of end-of-line character or characters the current format uses.  I would have used to word "linefeed" where you use "newline" above, as that's the name of that ASCII character.  Am I wrong?  I guess with Unix a linefeed is a newline, but not in other formats.

             
            • Nobody/Anonymous

              I've actually had to process files generated by an Oracle report writer that has occasional newlines (newline is a unique character and not the same as a form-feed which implies a new page) in one of the fields being extracted - the actual end-of-lines have both carriage-return (decimal 13) and newline (decimal 10).

              The ascii character definitions are the same regardless of system but Bill Gates and Steve Jobs had to invent their own end-of-lines (it seems :|)

               
              • pshute

                pshute - 2007-12-12

                "newline is a unique character and not the same as a form-feed which implies a new page"

                I didn't say formfeed, I said linefeed.  http://en.wikipedia.org/wiki/Newline agrees with my terminology.

                 
                • Nobody/Anonymous

                  > I didn't say formfeed, I said linefeed. http://en.wikipedia.org/wiki/Newline agrees with my terminology.

                  sorry, my stupid.

                  thanks for pointing to that wikipedia article - i'm boring enough to find it very interesting - i would call it plenty comprehensive - who knew - i've programmed in a few of the languages mentioned - some things i hadn't been aware of or forgot