copy regex captures to the clipboard

copy regex captures to the clipboard

11
Basic UserBasic User
11

    Jan 31, 2007#1

    hey group --

    First time poster. New UE user. Go easy on me. :lol:

    I'm looking to do a pretty simple task with a macro but can't quite work it out after an hour and a half of mucking about. I have a file as follows:

    Code: Select all

     34.a UnitTest12: xxy
     37.b  blah blahUnitTest:  yzz
     34.a UnitTest009: zyz
     42.c  yadda, UnitTestadda: xyz
     34.a UnitTest74: xxx
    I'd like to capture every occurance of "UnitTest\d.*" that has "34.a" in front of it, and append that to the clipboard string. The final result on the clipboard should look like this:
    ---------> UnitTest12, UnitTest009, UnitTest74

    The regex to grab the captures is not a problem, what I have is working fine In UE. (I'm using Perl style, NOT Unix or UE, here):
    ---------> \s34.a\s*(UnitTest\d.*)\s*[:]

    Where Im totally lost with UE is: How to append all the captures ($1) to the clipboard in one long string using a macro.

    Anyone have a macro snippet? Im probably approaching it all wrong by not looping or something.

    Tnx
    WZ

      Jan 31, 2007#2

      Hmmmm.....

      ...I've also been trying to use a Perl Positive Lookbehind to capture exactly what I need directly w/o using a capture submatch I originally posted.

      Instead of using this perl and trying to use the $1 capture in a macro:
      ------> \s34.a\s*(UnitTest\d.*)\s*[:]

      I thought I could do a "find" using this regex,(works great in Perl):
      ------> (?<=34.a\s*)U\w*

      But that doesn't work in UE v12.20 either. It returns: "You have entered an invalid expression". Doh.

      So Im still stuck without a regex I can use in the "find" macro command. hrmpffff. I'm obviously missing something very elementary here.

      wz

      344
      MasterMaster
      344

        Jan 31, 2007#3

        Hi Wow,

        well, a lookbehind ONLY works for plain text, if I understood it right.

        E.g. look here for "lookbehind": http://www.regular-expressions.info/refadv.html
        Since regular expressions cannot be applied backwards, the test inside the lookbehind can only be plain text.
        So I think you have to use your loop and a copyappend in your macro.

        rds bego
        Normally using all newest english version incl. each hotfix. Win 10 64 bit

        6,686585
        Grand MasterGrand Master
        6,686585

          Jan 31, 2007#4

          Use following macro with the macro property Continue if a Find with Replace not found checked for this macro.

          InsertMode
          ColumnModeOff
          HexOff
          UnixReOn
          ClearClipboard
          Loop
          Find RegExp "\s*34\.a\s*UnitTest\d+"
          IfFound
          Key HOME
          Find RegExp "UnitTest\d+"
          CopyAppend
          EndSelect
          Key LEFT ARROW
          Key RIGHT ARROW
          ","
          StartSelect
          Key LEFT ARROW
          CutAppend
          EndSelect
          Else
          ExitLoop
          EndIf
          EndLoop

          Add UnixReOff or PerlReOn (v12+ of UE) at the end of the macro if you do not use Unix style regular expressions by default - see search configuration. Macro command UnixReOn sets the regular expression option to Unix style.
          Best regards from an UC/UE/UES for Windows user from Austria

          344
          MasterMaster
          344

            Jan 31, 2007#5

            Hi Mofi,
            IfFound
            Key HOME
            Find RegExp "UnitTest\d+"
            that one is clever. I tried to "extract" the $1 anyhow, but a simple goto start of line and do another search only kicks it.

            n1, bego
            Normally using all newest english version incl. each hotfix. Win 10 64 bit

            11
            Basic UserBasic User
            11

              Jan 31, 2007#6

              Bego wrote:Well, a lookbehind ONLY works for plain text, if I understood it right.
              I think you're right, Bego. Once I used a literal string inside the lookback it was fine in UE.

              I have a tool called "RegexBuddy" that I used to create the incorrect lookback regex. Unfortunately, it DOES allow character pattern matches inside the lookback even though it shouldn't when set to run in perl.

              (BTW, RB is great inexpensive tool for learning regex even though it has a goofy azz name. You can set it to work for various flavors of regex such as perl, .net, 'nix, vbscript, etc.).

              Thanks for the heads up.

              Wz

                Jan 31, 2007#7

                Thanks Mofi.

                Good idea to backtrack and make your own "subselection capture". :lol:

                Also, good catch escaping my literal '.' with '\.' That's definitely what I should have used.

                -----------------
                Wow_Zow wrote:Thanks for all your help {Mofi} --- and thanks for being such a prolific poster. You saved me quite a bit of work with your hints and tips, as I read through the your regex and macro forum responses.

                tnx mate,
                Wz
                From a thread over in 'macros' that you helped with too.

                Cheers mate!
                Wz