Community
    • Login

    Select/Export certain text that appears above a different set of certain text - Two separate find queries

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    20 Posts 5 Posters 1.4k 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.
    • S
      StormyCalories @Alan Kilborn
      last edited by

      @Alan-Kilborn said in Select/Export certain text that appears above a different set of certain text - Two separate find queries:

      @StormyCalories

      Yea…so point the mouse at the little speech bubble with the ... in it, and see what it says when a popup appears.

      Wow, I had tried clicking on that speech bubble earlier and nothing happened. I clearly didn’t have the patience to just hover my mouse for a fraction of a second. Sorry about that!

      Here’s the full error message:

      241c7b96-511f-4224-b0bb-165a21392756-image.png

      Alan KilbornA 1 Reply Last reply Reply Quote 1
      • Alan KilbornA
        Alan Kilborn @StormyCalories
        last edited by

        @StormyCalories

        I think it all makes sense now.
        Pretty much your only choice is to work on your expression to make it so such a condition isn’t entered.
        That may or may not be possible.

        1 Reply Last reply Reply Quote 1
        • PeterJonesP
          PeterJones @StormyCalories
          last edited by PeterJones

          @StormyCalories ,

          My suggestion: If every Product Name ... { } ends with a } by itself on a line, change the instances of (?:(?!Product Name).) in the expression into (?:(?!^}).) , which will stop each section with } at the beginning of a line, instead of stopping at the next Product Name. If there’s actually whitespace before the }, then use (?:(?!^\h*}).) . As long as the number of characters from Product Name to } isn’t ever too huge, it should be able to handle the complexity. (If you have a megabyte of data within each record, that probably won’t work; but a few dozen lines shouldn’t be a problem, and probably not even a problem on a few hundred lines)

          S 1 Reply Last reply Reply Quote 2
          • CoisesC
            Coises @StormyCalories
            last edited by Coises

            @StormyCalories said in Select/Export certain text that appears above a different set of certain text - Two separate find queries:

            Is this a problem I can resolve by using a more powerful computer or is there some sort of maximum dataset size that I’m running into?

            No promises (I’m at the edge of my knowledge), but this might work:

            (?s)(?<=Product Name=")\w++(?=.*?(\.TRIGGER':=1|Product Name=(*THEN)(*FAIL)))

            S 1 Reply Last reply Reply Quote 2
            • S
              StormyCalories @PeterJones
              last edited by StormyCalories

              @PeterJones said in Select/Export certain text that appears above a different set of certain text - Two separate find queries:

              As long as the number of characters from Product Name to } isn’t ever too huge, it should be able to handle the complexity. (If you have a megabyte of data within each record, that probably won’t work; but a few dozen lines shouldn’t be a problem, and probably not even a problem on a few hundred lines)

              I see. That might be my biggest problem then. Each element can have upwards of 15,000 lines and half a million characters. Does this large of potential datasets scratch the whole idea of parsing the file with Notepad++?

              edit: I should add, the full file I’m working against can be about a half gig. Obviously, I have no problem splitting the file into multiple different smaller pieces, but the data within will still be very large and complex elements.

              1 Reply Last reply Reply Quote 0
              • S
                StormyCalories @Coises
                last edited by StormyCalories

                @Coises said in Select/Export certain text that appears above a different set of certain text - Two separate find queries:

                No promises (I’m at the edge of my knowledge), but this might work:

                (?s)(?<=Product Name=")\w++(?=.*?(.TRIGGER’:=1|Product Name=(*THEN)(*FAIL)))

                This actually seemed to solve the problem of having too much data within the element. I was able to successfully run this expression even on a file that had failed on the original expression in this thread. It’s still not working on the full file that I have and I’m still trying to track down why that might be. I’ve been able to see that if there are 10’s of thousands of lines of elements between two positive elements, it seems to fail. I’m attempting to figure out how much it can parse before breaking.

                edit: This seems to break whenever the total file line size is greater than 165k lines or so.

                CoisesC 1 Reply Last reply Reply Quote 0
                • CoisesC
                  Coises @StormyCalories
                  last edited by

                  @StormyCalories said in Select/Export certain text that appears above a different set of certain text - Two separate find queries:

                  I’ve been able to see that if there are 10’s of thousands of lines of elements between two positive elements, it seems to fail. I’m attempting to figure out how much it can parse before breaking.

                  Perhaps you could first use something like:

                  Find what : (?-s)^.*?(\R|(\.TRIGGER':=1|Product Name=)(*THEN)(*FAIL))
                  Replace with : (leave empty)

                  on a copy of your file to remove all the lines that don’t affect the search.

                  S 1 Reply Last reply Reply Quote 1
                  • S
                    StormyCalories @Coises
                    last edited by

                    @Coises

                    That is a really intriguing idea. So simple and I would never have considered it.

                    I shall report back. Thank you!

                    CoisesC 1 Reply Last reply Reply Quote 0
                    • CoisesC
                      Coises @StormyCalories
                      last edited by Coises

                      @StormyCalories said in Select/Export certain text that appears above a different set of certain text - Two separate find queries:

                      @Coises

                      That is a really intriguing idea. So simple and I would never have considered it.

                      Perhaps even better:

                      Find what : ^.*?((Product Name=|\.TRIGGER':=1)|\R|\z)
                      Replace with : $2

                      S 1 Reply Last reply Reply Quote 2
                      • S
                        StormyCalories @Coises
                        last edited by

                        @Coises
                        Well it took 35 minutes for my PC to chug through with the search/replace but after it finally finished, all the expressions by everyone above works against the data.

                        Thank all of you so much!

                        1 Reply Last reply Reply Quote 0
                        • guy038G
                          guy038
                          last edited by guy038

                          Hello, @stormycalories, @peterjones, @alan-kilborn, @Coises and all,

                          Yeah, interesting topic !

                          First, I would simplified the @peterjones’s regex :

                          • SEARCH (?s)(?<=Product Name=")(?:(?!Product Name).)*?(?="((?:(?!Product Name).)+?)(?=.TRIGGER':=1))

                          As :

                          • SEARCH (?xs) (?<= Product[ ]Name=" ) \w+ (?= " ( (?! Product[ ]Name ). )+? \. TRIGGER':=1 .+? \} )

                          Because the whole regex would search for some word chars only, instead of standard chars


                          Now, @coises, your use of backtracking control verbs, in the below regex, is quite clever !

                          • SEARCH (?s)(?<=Product Name=")\w++(?=.*?(\.TRIGGER':=1|Product Name=(*THEN)(*FAIL)))

                          I personally get used to follow this method :

                          https://www.rexegg.com/backtracking-control-verbs.html#skipfail

                          As it is said, the generic regex <.....(*SKIP)(*FAIL)|.....> syntax just means <What we DON'T want | What we DO want> !

                          In this example, this end up to :

                          • SEARCH (?xs) (?<= Product[ ]Name=" ) \w+ (?= .*? ( Product[ ]Name= (*SKIP) (*FAIL) | \. TRIGGER':=1 ) )

                          In the same way, @coises, I would change your regex S/R, which deletes any line which does NOT contain the Product Name NOR the .TRIGGER':=1 strings :

                          • SEARCH (?-s)^.*?(\R|(\.TRIGGER':=1|Product Name=)(*THEN)(*FAIL))

                          • REPLACE Leave EMPTY

                          by this one :

                          • SEARCH (?x-is) ^ .* (?: Product[ ]Name= | \.TRIGGER':=1 ) (*SKIP) (*F) | ^ .* \R

                          • REPLACE Leave EMPTY

                          Which could be expressed as :

                          • IF, from beginning of current line, it is followed, further on, by, either, the Product Name= or the .TRIGGER':=1 strings, we DO NOT want to delete the currrent line

                          • ELSE, we DO want to delete the current line


                          Finally, I admit that your final try, for the same purpose :

                          • SEARCH (?-s)^.*?((Product Name=|\.TRIGGER':=1)|\R|\z)

                          • REPLACE $2

                          seems the best one !

                          I also thought of this equivalent syntax :

                          • SEARCH (?x-s) ^ (?! .* (?: Product[ ]Name= | \. TRIGGER':=1 ) ) .* \R

                          • REPLACE Leave EMPTY

                          Where the search comes from (?x-s) ^ (?! (?: .* Product[ ]Name= | .* \. TRIGGER':=1 ) ) .* \R


                          Note that the regex part :

                          
                               (?! (?: .* Product[ ]Name= | .* \. TRIGGER':=1 ) )
                                       ------------------   -----------------
                                                A                B
                          

                          Means, in a logical way :

                          
                               NOT ( ( .* Product Name=   OR   .* .TRIGGER':=1 ) )
                                       ----------------        ---------------
                                                A                     B
                          

                          which, in turn, can be expressed as :

                               NOT ( .* Product Name= )   AND   NOT ( .* .TRIGGER':=1 )
                                     ----------------                 ---------------
                                            A                                B
                          

                          Thus, meaning :

                          Consider all the current line and its EOL chars, which do NOT contain the Product Name= NOR  the .TRIGGER':=1 strings, and delete it !

                          Best Regards,

                          guy038

                          CoisesC 1 Reply Last reply Reply Quote 4
                          • CoisesC
                            Coises @guy038
                            last edited by

                            @guy038 said in Select/Export certain text that appears above a different set of certain text - Two separate find queries:

                            https://www.rexegg.com/backtracking-control-verbs.html#skipfail

                            That entire page is very useful. Thanks!

                            I was reading the Boost regex documentation to which Notepad++ documentation links and experimenting, trying to figure out what those terse descriptions meant. I was sure there should be a way to reduce the matching complexity with verbs, but I didn’t really know how they work.

                            (*SKIP)(*FAIL) is clearly the better choice for this case.

                            1 Reply Last reply Reply Quote 2
                            • guy038G
                              guy038
                              last edited by

                              Hello, @coises and All,

                              You may, also, refer to this topic, that I wrote after that a new version of the Boost regex library comes out and was available within Notepad++ :

                              https://community.notepad-plus-plus.org/topic/19632/new-backtracking-control-verbs-feature-available-since-notepad-v7-7/1

                              BR

                              guy038

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