• Login
Community
  • Login

Finding and deleting a series of lines

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
15 Posts 5 Posters 4.8k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    Alan Kilborn @James
    last edited by Alan Kilborn Jun 17, 2021, 12:38 AM Jun 17, 2021, 12:36 AM

    @James

    it’s saying there’s no occurances of that command ((?-is)(^.+\R){n}.Expression.\R(?1){m}).

    Well, hopefully you understand that this is a formula and not something you would directly input:

    ddc4710f-c4c0-45ea-b302-d868731ecd36-image.png

    This, however, is an application of that formula, and thus could be directly entered into the Find what box:

    (?-is)^(.+\R){1}.*1234.*\R(?1){4}

    1 Reply Last reply Reply Quote 1
    • A
      Alan Kilborn @James
      last edited by Jun 17, 2021, 12:37 AM

      @James said in Finding and deleting a series of lines:

      I assume it’s because it’s searching for it as a string, not as a command.

      I’m confused by this part.
      There is no searching by command, there is only searching by string.

      A 1 Reply Last reply Jun 17, 2021, 11:14 AM Reply Quote 1
      • J
        James
        last edited by Jun 17, 2021, 8:10 AM

        I should’ve phrased that better. When I try inputting that command in the find what section, it seems to be searching for it as a string, rather than as some sort of formula like you said.

        T 1 Reply Last reply Jun 17, 2021, 8:33 AM Reply Quote 0
        • T
          Terry R @James
          last edited by Jun 17, 2021, 8:33 AM

          @James said in Finding and deleting a series of lines:

          it seems to be searching for it as a string, rather than as some sort of formula like you said.

          This is a regular expression so the search mode MUST be regular expression. That was the 3rd highlight in the image @Alan-Kilborn provided above.

          Terry

          1 Reply Last reply Reply Quote 1
          • A
            Alan Kilborn @Alan Kilborn
            last edited by Jun 17, 2021, 11:14 AM

            @Alan-Kilborn said in Finding and deleting a series of lines:

            There is no searching by command, there is only searching by string.

            I suppose that statement I made was misleading, as a “regular expression” rather is more like a formula/command than it is like a string. Sorry for any confusion I brought. :-)

            1 Reply Last reply Reply Quote 1
            • J
              James
              last edited by Jun 17, 2021, 4:57 PM

              Well even when I use the find what section and regular expression options, it seems to be searching for it as a string regardless. 56fe8fb2-fc01-4025-99e4-eebc8649d599-image.png 0e93ee55-9189-472e-9899-ef3d08970ab2-image.png

              A P 2 Replies Last reply Jun 17, 2021, 5:11 PM Reply Quote 1
              • A
                Alan Kilborn @James
                last edited by Jun 17, 2021, 5:11 PM

                @James

                Hmm. Yea, I see what you mean. I was using the formula to try to find the text “copy” in the N++ license.txt file. Even though I tweaked the formula a bit so that it would ignore case, I was getting no hits.

                As @guy038 wrote the formula, I’ll let him comment on what might not quite be right there.

                1 Reply Last reply Reply Quote 1
                • P
                  PeterJones @James
                  last edited by PeterJones Jun 17, 2021, 5:32 PM Jun 17, 2021, 5:30 PM

                  @James ,

                  It works on a single file for me.

                  ea3f2aad-bd2c-4c05-baea-8896d4ca3eac-image.png

                  eight
                  seven
                  six
                  five
                  four
                  three
                  two
                  one
                  1234
                  one
                  two
                  three
                  four
                  five
                  six
                  seven
                  eight
                  nine
                  ten
                  eleven
                  twelve
                  thirteen
                  fourteen
                  fifteen
                  

                  FIND = (?-is)^(.+\R){7}.*1234.*\R(?1){14}

                  Taking @Alan-Kilborn’s example, I see the problem. The (.+\R) assumes there’s at least one character on every line before or after the matching text. The license.txt has blank lines throughout, so there usually aren’t many lines before and after. So change to (.*\R) => FIND = (?i-s)^(.*\R){7}.*copy.*\R(?1){14} (I also changed to (?i-s) so that the copy was case-insensitive, as Alan mentioned.)

                  0dcfda87-bb8f-43e5-b358-64696bcd69e1-image.png

                  So if your real data has any lines that are blank (just newlines), you will need to use .* instead of .+

                  1 Reply Last reply Reply Quote 2
                  • G
                    guy038
                    last edited by guy038 Jun 18, 2021, 3:33 PM Jun 18, 2021, 3:29 PM

                    Hello @james, @lan-kilborn, @terry-r, @peterjones and All,

                    @james : Thanks to @peterjones, you have the right solution !

                    So, in summary :

                    • To delete some non-empty lines before and/or after a line, containing Expression, with this exact case :

                      • SEARCH (?-is)(^.+\R){n}.*Expression.*\R(?1){m}

                    • To delete some non-empty lines before and/or after a line, containing Expression, whatever its case

                      • SEARCH (?i-s)(^.+\R){n}.*Expression.*\R(?1){m}

                    • To delete some lines, possibly empty, before and/or after a line, containing Expression, with this exact case :

                      • SEARCH (?-is)(^.*\R){n}.*Expression.*\R(?1){m}

                    • To delete some lines, possibly empty, before and/or after a line, containing Expression, whatever its case

                      • SEARCH (?i-s)(^.*\R){n}.*Expression.*\R(?1){m}

                    • where n represents the number of lines before the line containing Expression ( n >= 0 )

                    • and     m represents the number of lines after    the line containing Expression ( m >= 0 )

                    Best Regards,

                    guy038

                    A 1 Reply Last reply Jun 19, 2021, 10:55 AM Reply Quote 0
                    • A
                      Alan Kilborn @guy038
                      last edited by Jun 19, 2021, 10:55 AM

                      @guy038

                      Actually, what you’ve specified is for finding some… , not deleting some…

                      To delete, we need to specify:

                      • SEARCH (as above)
                      • REPLACE leave this field blank

                      :-)

                      1 Reply Last reply Reply Quote 1
                      15 out of 15
                      • First post
                        15/15
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors