Loading ...
Sorry, an error occurred while loading the content.

Re: [NTO] How to delete all lines that do not contain a Z using a one-line regex?

Expand Messages
  • Roy Herring
    I figured it out! ^!REPLACE ^[^ z]+ n rwsati ... From: Roy Herring To: ntb-OffTopic@yahoogroups.com Sent: Tuesday, December 28, 2004 10:12 PM Subject:
    Message 1 of 6 , Dec 28, 2004
    • 0 Attachment
      I figured it out!

      ^!REPLACE "^[^\z]+\n" >> "" rwsati
      ----- Original Message -----
      From: Roy Herring
      To: ntb-OffTopic@yahoogroups.com
      Sent: Tuesday, December 28, 2004 10:12 PM
      Subject: [NTO] How to delete all lines that do not contain a Z using a one-line regex?


      How to delete all lines that do not contain a Z using a one-line regex?

      This doesn't work: ^!REPLACE "^[^z]$" >> "" rwsati

      Thanks,
      Roy

      One way that I can think of requires 3 lines:

      ^!Info Flag (with * in col 1) all lines that do contain Z.
      ^!REPLACE "^{.*z.*}" >> "*\1" rwsati
      ^!Info Delete all lines that do not contain * in col 1.
      ^!REPLACE "^[^\*].*\n" >> "" rwsati
      ^!Info Remove all *'s in col 1.
      ^!REPLACE "^\*" >> "" rwsati


      [Non-text portions of this message have been removed]


      Yahoo! Groups Sponsor
      ADVERTISEMENT





      ------------------------------------------------------------------------------
      Yahoo! Groups Links

      a.. To visit your group on the web, go to:
      http://groups.yahoo.com/group/ntb-OffTopic/

      b.. To unsubscribe from this group, send an email to:
      ntb-OffTopic-unsubscribe@yahoogroups.com

      c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



      [Non-text portions of this message have been removed]
    • Alec Burgess
      ... FWIW: ^!replace (^[^z]* n)+ rwsa * instead of + will also get blank lines too (if desired) and ... wrapping with (....)+ will get each group of
      Message 2 of 6 , Dec 28, 2004
      • 0 Attachment
        Roy:

        > I figured it out!
        > ^!REPLACE "^[^\z]+\n" >> "" rwsati

        FWIW:

        ^!replace "(^[^z]*\n)+" >> "" rwsa

        * instead of + will also get blank lines too (if desired) and
        ... wrapping with (....)+ will get each group of lines with no "z" in one.

        Testing with a large file >3600 lines appears to give a speed improvement
        proportional (I think) to the number of blocks vs. number of lines.

        eg. In the random large sample file I choose it made 112 replacements
        *correctly* whereas without wrapping in (....)+ the first pass made 1788
        replacements, the next 868 replacements etc...

        I more frequently try to delete blank lines and found that
        "\n\n+" ---> "" instead of "\n\n" --> "" works faster and gets all of them
        in one pass instead of having to reexecute the replacemement multiple times!

        Regards ... Alec
        --

        ----- Original Message -----
        From: "Roy Herring" <roynancy@...>
        To: <ntb-OffTopic@yahoogroups.com>
        Sent: Tuesday, December 28, 2004 23:50
        Subject: [gla: Re: [NTO] How to delete all lines that do not contain a Z
        using a one-line regex?


        >
        > I figured it out!
        >
        > ^!REPLACE "^[^\z]+\n" >> "" rwsati
        > ----- Original Message -----
        > From: Roy Herring
        > To: ntb-OffTopic@yahoogroups.com
        > Sent: Tuesday, December 28, 2004 10:12 PM
        > Subject: [NTO] How to delete all lines that do not contain a Z using a
        one-line regex?
        >
        >
        > How to delete all lines that do not contain a Z using a one-line regex?
        >
        > This doesn't work: ^!REPLACE "^[^z]$" >> "" rwsati
        >
        > Thanks,
        > Roy
        >
        > One way that I can think of requires 3 lines:
        >
        > ^!Info Flag (with * in col 1) all lines that do contain Z.
        > ^!REPLACE "^{.*z.*}" >> "*\1" rwsati
        > ^!Info Delete all lines that do not contain * in col 1.
        > ^!REPLACE "^[^\*].*\n" >> "" rwsati
        > ^!Info Remove all *'s in col 1.
        > ^!REPLACE "^\*" >> "" rwsati
        >
        >
        > [Non-text portions of this message have been removed]
        >
        >
        > Yahoo! Groups Sponsor
        > ADVERTISEMENT
        >
        >
        >
        >
        >
        > --------------------------------------------------------------------------
        ----
        > Yahoo! Groups Links
        >
        > a.. To visit your group on the web, go to:
        > http://groups.yahoo.com/group/ntb-OffTopic/
        >
        > b.. To unsubscribe from this group, send an email to:
        > ntb-OffTopic-unsubscribe@yahoogroups.com
        >
        > c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of
        Service.
        >
        >
        >
        > [Non-text portions of this message have been removed]
        >
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        >
        >
        >
      • Roy Herring
        Thanks Alec, I realized last night that my solution was flawed because it will not delete 2 lines in a row, such as: z 1 2 3 4 5 6 z ... From: Alec Burgess To:
        Message 3 of 6 , Dec 29, 2004
        • 0 Attachment
          Thanks Alec,
          I realized last night that my solution was flawed because it will not delete 2 lines in a row, such as:

          z
          1
          2
          3
          4
          5
          6
          z

          ----- Original Message -----
          From: Alec Burgess
          To: ntb-OffTopic@yahoogroups.com
          Sent: Wednesday, December 29, 2004 1:27 AM
          Subject: Re: Re: [NTO] How to delete all lines that do not contain a Z using a one-line regex?


          Roy:

          > I figured it out!
          > ^!REPLACE "^[^\z]+\n" >> "" rwsati

          FWIW:

          ^!replace "(^[^z]*\n)+" >> "" rwsa

          * instead of + will also get blank lines too (if desired) and
          ... wrapping with (....)+ will get each group of lines with no "z" in one.

          Testing with a large file >3600 lines appears to give a speed improvement
          proportional (I think) to the number of blocks vs. number of lines.

          eg. In the random large sample file I choose it made 112 replacements
          *correctly* whereas without wrapping in (....)+ the first pass made 1788
          replacements, the next 868 replacements etc...

          I more frequently try to delete blank lines and found that
          "\n\n+" ---> "" instead of "\n\n" --> "" works faster and gets all of them
          in one pass instead of having to reexecute the replacemement multiple times!

          Regards ... Alec
          --

          ----- Original Message -----
          From: "Roy Herring" <roynancy@...>
          To: <ntb-OffTopic@yahoogroups.com>
          Sent: Tuesday, December 28, 2004 23:50
          Subject: [gla: Re: [NTO] How to delete all lines that do not contain a Z
          using a one-line regex?


          >
          > I figured it out!
          >
          > ^!REPLACE "^[^\z]+\n" >> "" rwsati
          > ----- Original Message -----
          > From: Roy Herring
          > To: ntb-OffTopic@yahoogroups.com
          > Sent: Tuesday, December 28, 2004 10:12 PM
          > Subject: [NTO] How to delete all lines that do not contain a Z using a
          one-line regex?
          >
          >
          > How to delete all lines that do not contain a Z using a one-line regex?
          >
          > This doesn't work: ^!REPLACE "^[^z]$" >> "" rwsati
          >
          > Thanks,
          > Roy
          >
          > One way that I can think of requires 3 lines:
          >
          > ^!Info Flag (with * in col 1) all lines that do contain Z.
          > ^!REPLACE "^{.*z.*}" >> "*\1" rwsati
          > ^!Info Delete all lines that do not contain * in col 1.
          > ^!REPLACE "^[^\*].*\n" >> "" rwsati
          > ^!Info Remove all *'s in col 1.
          > ^!REPLACE "^\*" >> "" rwsati
          >
          >
          > [Non-text portions of this message have been removed]
          >
          >
          > Yahoo! Groups Sponsor
          > ADVERTISEMENT
          >
          >
          >
          >
          >
          > --------------------------------------------------------------------------
          ----
          > Yahoo! Groups Links
          >
          > a.. To visit your group on the web, go to:
          > http://groups.yahoo.com/group/ntb-OffTopic/
          >
          > b.. To unsubscribe from this group, send an email to:
          > ntb-OffTopic-unsubscribe@yahoogroups.com
          >
          > c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of
          Service.
          >
          >
          >
          > [Non-text portions of this message have been removed]
          >
          >
          >
          >
          >
          > Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
          >
          >


          Yahoo! Groups Sponsor
          ADVERTISEMENT





          ------------------------------------------------------------------------------
          Yahoo! Groups Links

          a.. To visit your group on the web, go to:
          http://groups.yahoo.com/group/ntb-OffTopic/

          b.. To unsubscribe from this group, send an email to:
          ntb-OffTopic-unsubscribe@yahoogroups.com

          c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



          [Non-text portions of this message have been removed]
        • Roy Herring
          Can anyone explain why adjacent lines on the following regex not deleted? ^!REPLACE ^[^ z]* n rwasti Alec s solution is superior, but I am trying to
          Message 4 of 6 , Dec 30, 2004
          • 0 Attachment
            Can anyone explain why adjacent lines on the following regex not deleted?
            ^!REPLACE "^[^\z]*\n" >> "" rwasti
            Alec's solution is superior, but I am trying to understand more about how regex works.
            Input:
            1
            2
            3
            4
            Output:
            2
            4
            All of the lines should have been deleted.

            This will not get adjacent lines on 1st pass
            ^!REPLACE "^[^\z]*\n" >> "" rwasti
            Alec's method works perfectly
            ^!replace "(^[^z]*\n)+" >> "" rwsa
            One at a time works (w/o the 'a' in rwsti)
            ^!REPLACE "^[^\z]*\n" >> "" rwsti

            Thanks,
            Roy

            Roy:

            > I figured it out!
            > ^!REPLACE "^[^\z]+\n" >> "" rwsati

            FWIW:

            ^!replace "(^[^z]*\n)+" >> "" rwsa

            * instead of + will also get blank lines too (if desired) and
            ... wrapping with (....)+ will get each group of lines with no "z" in one.

            Testing with a large file >3600 lines appears to give a speed improvement
            proportional (I think) to the number of blocks vs. number of lines.

            eg. In the random large sample file I choose it made 112 replacements
            *correctly* whereas without wrapping in (....)+ the first pass made 1788
            replacements, the next 868 replacements etc...

            I more frequently try to delete blank lines and found that
            "\n\n+" ---> "" instead of "\n\n" --> "" works faster and gets all of them
            in one pass instead of having to reexecute the replacemement multiple times!

            Regards ... Alec
            --

            ----- Original Message -----
            From: "Roy Herring" <roynancy@...>
            To: <ntb-OffTopic@yahoogroups.com>
            Sent: Tuesday, December 28, 2004 23:50
            Subject: [gla: Re: [NTO] How to delete all lines that do not contain a Z
            using a one-line regex?


            >
            > I figured it out!
            >
            > ^!REPLACE "^[^\z]+\n" >> "" rwsati
            > ----- Original Message -----
            > From: Roy Herring
            > To: ntb-OffTopic@yahoogroups.com
            > Sent: Tuesday, December 28, 2004 10:12 PM
            > Subject: [NTO] How to delete all lines that do not contain a Z using a
            one-line regex?
            >
            >
            > How to delete all lines that do not contain a Z using a one-line regex?
            >
            > This doesn't work: ^!REPLACE "^[^z]$" >> "" rwsati
            >
            > Thanks,
            > Roy
            >
            > One way that I can think of requires 3 lines:
            >
            > ^!Info Flag (with * in col 1) all lines that do contain Z.
            > ^!REPLACE "^{.*z.*}" >> "*\1" rwsati
            > ^!Info Delete all lines that do not contain * in col 1.
            > ^!REPLACE "^[^\*].*\n" >> "" rwsati
            > ^!Info Remove all *'s in col 1.
            > ^!REPLACE "^\*" >> "" rwsati
            >
            >

            [Non-text portions of this message have been removed]
          • Don - htmlfixit.com
            ... If you check back a couple of weeks we discussed what appears to be a bug in the regex. Just loop until no replacements occur and it will do it. The bug
            Message 5 of 6 , Dec 30, 2004
            • 0 Attachment
              Roy Herring wrote:
              > Can anyone explain why adjacent lines on the following regex not deleted?
              > ^!REPLACE "^[^\z]*\n" >> "" rwasti
              > Alec's solution is superior, but I am trying to understand more about how regex works.

              If you check back a couple of weeks we discussed what appears to be a
              bug in the regex. Just loop until no replacements occur and it will do
              it. The bug doesn't seem to exist when you use seach and replace dialog
              box, but does in clips. That thread involved replacing all lines with
              only numbers on them if I remember right.
            • abairheart
              ... deleted? ... I m not sure if this is the correct explanation, but it s how it seems to me: Your search expression starts at the beginning of the line ^ .
              Message 6 of 6 , Dec 30, 2004
              • 0 Attachment
                --- In ntb-OffTopic@yahoogroups.com, "Roy Herring" <roynancy@e...>
                wrote:
                > Can anyone explain why adjacent lines on the following regex not
                deleted?
                > ^!REPLACE "^[^\z]*\n" >> "" rwasti

                I'm not sure if this is the correct explanation, but it's how it
                seems to me:

                Your search expression starts at the beginning of the line "^". Then
                you remove the END of the line, "\n" which is also the beginning of
                the next line. Thus the search starts AFTER the beginning of the next
                line. The next thing that matches the entire expression is the
                following line (skipping one).


                > Alec's solution is superior, but I am trying to understand more
                about how regex works.
                > Input:
                > 1
                > 2
                > 3
                > 4
                > Output:
                > 2
                > 4


                ...

                >

                > Alec's method works perfectly
                > ^!replace "(^[^z]*\n)+" >> "" rwsa

                The reason this works is, that the search phrase, including the end
                of the line, are inside parenthesies, and the repetition operator "+"
                outside of the search expression. The replace does not start until
                the reg exp engine finds ALL it can to satisfy its greedy little maw.
                I.e. multiple lines.

                As I said, I'm guessing at this, not knowing all that much about the
                origin of NoteTab's reg exp engine. But perhaps it willmake sense to
                you as well.


                Abair.
              Your message has been successfully submitted and would be delivered to recipients shortly.