Community
    • Login

    Find and remove everything else

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    17 Posts 4 Posters 2.9k 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.
    • Terry RT
      Terry R
      last edited by Terry R

      @Anthony-Noriega said in Find and remove everything else:

      Close, but the pattern you have is off…on the end

      My solution was:
      Find What:(?s)\G/\.\*([^.]+)\.\*/|.+?(?=\z|/\.\*)
      Replace With:?1\1\r\n
      again a regular expression so search mode is regular expression.

      Where (again) leaning toothpicks are all around.

      Cheers
      Terry

      PS I should add there will likely be a last empty line, just a side effect of how the regex works. Should be easy enough to remove that afterwards.

      1 Reply Last reply Reply Quote 2
      • Anthony NoriegaA
        Anthony Noriega
        last edited by

        @Terry-R said in Find and remove everything else:

        (?s)\G/.*([^.]+).*/|.+?(?=\z|/.*)
        That fixed it, thank you all for your help.

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

          @Anthony-Noriega said in Find and remove everything else:

          Close, but the pattern you have is off…

          Yes, my bad on that. :-(

          Too bad we couldn’t have seen this from the very beginning:
          Imgur

          Anthony NoriegaA 1 Reply Last reply Reply Quote 0
          • Anthony NoriegaA
            Anthony Noriega @Alan Kilborn
            last edited by

            @Alan-Kilborn Rookie mistake… i didnt realize the formatter was gonna make me look like a bonehead.

            Alan KilbornA 1 Reply Last reply Reply Quote 2
            • Alan KilbornA
              Alan Kilborn @Anthony Noriega
              last edited by Alan Kilborn

              @Anthony-Noriega said in Find and remove everything else:

              look like a bonehead.

              No worries.
              We see that kind of thing CONSTANTLY here!
              :-)
              The important part is we are marking your problem SOLVED!

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

                Hello, @Anthony-Noriega, @alan-kilborn, @terry-r and All,

                I know, I’m a bit late :-) Here is my solution !

                Assuming that the exact syntax is :

                /.*keyword.*/
                

                SEARCH (?s).+?/\.\*(.+?)\.\*/|.+

                REPLACE ?1\1\r\n

                Notes :

                • First, the (?s) syntax means that the regex . char will match any single character, even an EOL one

                • Then , in two parts of the search expression, the regex syntax .+? represents the shortest non-null range of characters till, either, the strings /.* or .*/

                • Because of the regex symbols * and ., these characters must be escaped with an slash, so the form \.\*

                • As the second .+? syntax is embedded between parentheses, the second range of chars ( each keyword ) is stored as group 1

                • Finally , then no more keyword exists, the second alternative .+ looks for the greatest non-null range of characters till… the very end of file

                • In replacement, the conditional structure ?1\1\r\n means that if the group 1 exists, it is rewritten \1, followed with a line break \r\n. When the second alternative of the search occurs, no group is involved. So nothing occurs, and the last range of text, after the last keyword, is simply deleted

                Best Regards,

                guy038

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

                  @guy038

                  But really, Guy, there isn’t anything new here over what you posted HERE – with the removal of the ^ as discussed a bit later in that thread – it’s just an application of the other posting’s idea to slightly different data.

                  We probably should stop solving the specific problems and just point people to the already-derived general solutions.

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

                    Hi, @lan-kilborn,

                    Yes, I agree that it looks like a redundant piece of information ! In fact, I was thinking to this old post, where I proposed a general method, for isolating literal strings or expressions matched by a given regex, rewritten on different lines :

                    https://notepad-plus-plus.org/community/topic/12710/marked-text-manipulation/8

                    That’s the reason why, in my previous post, I preferred to focus on the regexes’s explanations, thinking it could be useful to the OP, anyway !

                    But, Alan, you’re right : my post wasn’t really needed ;-))

                    Cheers,

                    guy038

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

                      @guy038

                      I had a further thought:

                      The thread I linked to earlier, and referred to in my post just above is entitled “Marked Text Manipulation”.

                      That relates to the current thread because a typical desire after marking some text is to copy only that text to another location, which is very similar to the topic of this “Find and remove everything else” thread.
                      In both cases you obtain the same effective result.

                      The new thought is that, at the time of the “Marked Text Manipulation” thread’s main discussion, there was no way to copy marked text without resorting to scripting. Now (7.9.1-ish) there is:

                      1f6bdae9-f91c-4b07-bfb6-5afebec8922b-image.png

                      Just press the indicated button after you already have marked some text.

                      I will put a similar not in that other thread as well.

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

                        Hi, @anthony-noriega, @alan-kilborn, @terry-r and All,

                        Oh, yes, Alan. You’re right ! Of course, I already downloaded the portable v7.9.1 version but I’m still “stuck” with the v7.8.5 version which explains why I didn"t notice this recent enhancement !

                        So, thanks to @scott-sumner, we just have to use the (?-s)/\.\*\K(.+?)(?=\.\*/) regex, click on the Mark All button to get all the keywords and, then, click on the Copy Marked Text button and paste the results on a new document. Nice !

                        BR

                        guy038

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