Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Copy Regular Expression Search Results to Clipboard

    Help wanted · · · – – – · · ·
    clipboard search copy results
    3
    5
    28507
    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.
    • Robert Or Janet Diebel
      Robert Or Janet Diebel last edited by

      Really appreciate Notepad++, and was extremely happy to find ths “Search” included Regular Expressions! WOW!
      I used them and got exactly what I wanted highlighted… GREAT.
      However, when I tried to figure out how to copy the search results, I could not find out how…
      So close, but failure.
      Is there a way to copy search results to the clipboard?

      All help much appreciated!
      Bob

      1 Reply Last reply Reply Quote 0
      • Jim Dailey
        Jim Dailey last edited by

        Right mouse click in the find results window and pick Select all.
        Right mouse click in the find results window and pick Copy.

        1 Reply Last reply Reply Quote 0
        • Robert Or Janet Diebel
          Robert Or Janet Diebel last edited by

          Yes, this gives me every line containing the RegEx, but I just want the part the RegEx selected.
          Is there a way to get just that?

          1 Reply Last reply Reply Quote 0
          • Jim Dailey
            Jim Dailey last edited by

            I’m not 100% sure what you want to copy.

            If you want to copy some particular matching string, you can double click on the line in the search window, which will open (if necessary) the file and move the focus to it. The text that matched the regex will be selected, so you can then copy it to the clipboard.

            If you want to copy all the occurrences of matching strings, then I think you are out of luck (at least as far as Notepad++ goes). You could probably use a scripting language like GAWK, PERL, or Python to spit out just the matching text in a file, which might get you close to what you want.

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

              Hello Robert and Janet,

              Seemingly, as you seem comfortable with regular expressions, you could easily extract the matched strings with a simple regex ?

              For instance, let’s suppose the simple list of people of an enterprise, below :

              Occupation   Age   Title     Name    Forename
              ---------------------------------------------
              Technician    50    Mr      SMITH     John
              Secretary     25    Miss    BROWN     Amy
              Manager       40    Mrs     HARPER    Edith
              .......       ..    ...     ......    .....
              

              and that you would like to do some statistics, depending on the age and/or the title of these persons. Then, you would need, ( may be for confidentiality ! ) to extract, ONLY, the second and third columns of that list. If so :

              • Copy this list in an new tab of N++

              • Perform the S/R, below, in Regular expression search mode :

              SEARCH .*?(\d+ +\w+).*

              REPLACE \1


              If, in addition, you would prefer to delete any line, that does NOT match the regex, use, instead the S/R below :

              SEARCH .*?(\d+ +\w+).*|^.*\R

              REPLACE \1

              You’ll only get the strings matched by the regex, below :

              50    Mr
              25    Miss
              40    Mrs
              

              Note :

              If the regex can’t be found, the first part of the alternative is not matched ( so, the group \1 doesn’t exist ) but the second part of the alternative is, obviously, always matched, as it matches an entire line, with its EOL character(s)

              Best Regards,

              guy038

              1 Reply Last reply Reply Quote 1
              • First post
                Last post
              Copyright © 2014 NodeBB Forums | Contributors