Loading ...
Sorry, an error occurred while loading the content.

Re: Search and Replace and increment number at the same time

Expand Messages
  • Sheri
    ... Yes, the clip code to do it follows. ^!Jump Doc_Start ... ^!Find /y= K d+ RS ^!IfError Done ^!InsertText ^$Calc(^$GetSelection$ + 20)$ ^!Goto RepLoop ...
    Message 1 of 9 , Sep 30, 2009
    • 0 Attachment
      --- In ntb-clips@yahoogroups.com, "isola_60185" <isola_60185@...> wrote:
      >
      > Might be way off base, I am not a seasoned NoteTab Pro user, nor
      > am I a progammer.
      >
      > If I have strings in a txt file that look like this:
      >
      > /y=250
      > /y=255
      > /y=260
      >
      > Is there any way I can Search and Replace so that I can increment
      > each number (by 20 for example) so that the numbers look like:
      >
      > /y=270
      > /y=275
      > /y=280
      >
      > I have about 100 occurences of these numbers (they are for xy
      > coordinates) and I need to increment them. There are _no_ numbers
      > that repeat, all our unique.
      >
      > I think I'm asking if NoteTab can recognize these strings as
      > numbers and then do a math operation on them but using a wildcard
      > as the search.
      >
      > So search for /y=* and substitute the wildcard with the number+20.
      >
      > Thanks.
      >

      Yes, the clip code to do it follows.

      ^!Jump Doc_Start
      :RepLoop
      ^!Find "/y=\K\d+" RS
      ^!IfError Done
      ^!InsertText ^$Calc(^$GetSelection$ + 20)$
      ^!Goto RepLoop
      :Done
      ^!Prompt All Done
      ;end of clip

      Regards,
      Sheri
    • Don Daugherty
      ... Sheri, What is K in the ^!Find command? I don t find it documented in the Clip Programming Help file. Don Daugherty
      Message 2 of 9 , Oct 1, 2009
      • 0 Attachment
        Sheri wrote:
        > Yes, the clip code to do it follows.
        >
        > ^!Jump Doc_Start
        > :RepLoop
        > ^!Find "/y=\K\d+" RS
        > ^!IfError Done
        > ^!InsertText ^$Calc(^$GetSelection$ + 20)$
        > ^!Goto RepLoop
        > :Done
        > ^!Prompt All Done
        > ;end of clip
        >
        > Regards,
        > Sheri
        >
        Sheri,
        What is \K in the ^!Find command? I don't find it documented in the
        Clip Programming Help file.
        Don Daugherty
      • Sheri
        ... Hi Don, You should find it in the Regular Expressions Help file. Everything before and after the K has to match, but the part before the K gets
        Message 3 of 9 , Oct 1, 2009
        • 0 Attachment
          --- In ntb-clips@yahoogroups.com, Don Daugherty <daugherty@...> wrote:
          >
          > Sheri wrote:
          > > Yes, the clip code to do it follows.
          > >
          > > ^!Jump Doc_Start
          > > :RepLoop
          > > ^!Find "/y=\K\d+" RS
          > > ^!IfError Done
          > > ^!InsertText ^$Calc(^$GetSelection$ + 20)$
          > > ^!Goto RepLoop
          > > :Done
          > > ^!Prompt All Done
          > > ;end of clip
          > >
          > > Regards,
          > > Sheri
          > >
          > Sheri,
          > What is \K in the ^!Find command? I don't find it documented in
          > the Clip Programming Help file.
          > Don Daugherty
          >

          Hi Don,

          You should find it in the Regular Expressions Help file. Everything before and after the \K has to match, but the part before the \K gets discarded. The regex help file calls it resetting the match start.

          Regards,
          Sheri
        • Don Daugherty
          ... Thanks. It was there all along; I just didn t get it.
          Message 4 of 9 , Oct 5, 2009
          • 0 Attachment
            Sheri wrote:
            >> What is \K in the ^!Find command?
            > Hi Don,
            >
            > You should find it in the Regular Expressions Help file. Everything before and after the \K has to match, but the part before the \K gets discarded. The regex help file calls it resetting the match start.
            >
            > Regards,
            > Sheri
            Thanks. It was there all along; I just didn't get it.
          • Alec Burgess
            Sheri (silvermoonwoman@comcast.net) wrote (in part) (on 2009-10-02 at ... (sorry for late response but I just got back from holiday - two weeks in Europe -
            Message 5 of 9 , Oct 11, 2009
            • 0 Attachment
              Sheri (silvermoonwoman@...) wrote (in part) (on 2009-10-02 at
              00:22):
              > --- In ntb-clips@yahoogroups.com, Don Daugherty <daugherty@...> wrote:
              > >
              > > Sheri wrote:
              > > > Yes, the clip code to do it follows.
              ... SNIP
              > > > ^!Find "/y=\K\d+" RS
              ... SNIP
              > > What is \K in the ^!Find command? I don't find it documented in
              > > the Clip Programming Help file.
              > > Don Daugherty
              > >
              >
              > Hi Don,
              >
              > You should find it in the Regular Expressions Help file. Everything
              > before and after the \K has to match, but the part before the \K gets
              > discarded. The regex help file calls it resetting the match start.

              (sorry for late response but I just got back from holiday - two weeks in
              Europe - yippee!)

              I've seen you and Flo use the \K construct before w/o ever really
              understanding exactly how it worked.

              AFAICT - (?<=/y=)\d+ (where (?<...) is positive lookbehind) is
              equivalent to /y=\K\d+
              Now that I know what the \K does, is there any difference between the
              two (other than the simplicity of \K)

              FWIW: Sheri I'm sure knows this, but \K is a fairly recent addition to
              PCRE regex syntax. It's not yet supported by RegexBuddy as I discovered
              when I tried to test in it ;-)

              --
              Regards ... Alec (buralex@gmail & WinLiveMess - alec.m.burgess@skype)
            • flo.gehrke
              ... Alec, As you you wrote, K is similar to a Lookbehind Assertion. So (?
              Message 6 of 9 , Oct 11, 2009
              • 0 Attachment
                --- In ntb-clips@yahoogroups.com, Alec Burgess <buralex@...> wrote:

                > I've seen you (Sheri) and Flo use the \K construct before w/o
                > ever really understanding exactly how it worked.
                > Now that I know what the \K does, is there any difference between the
                > two (other than the simplicity of \K)

                Alec,

                As you you wrote, \K is similar to a Lookbehind Assertion. So (?<=Look)behind matches 'Lookbehind' without consuming the 'Look'. Look\Kbehind has the same effect.

                The difference is that the Lookbehind demands a fixed lenghth of the pattern whereas \K works with any length. That's why I often prefer \K.

                For example: (?<=\w+)behind produces an Error Message "Regex error: lookbehind assertion is not of fixed length." In contrast to that, \w+\Kbehind works fine.

                Regards,
                Flo
              • Alec Burgess
                flo.gehrke (flo.gehrke@t-online.de) wrote (in part) (on 2009-10-11 at ... Fixed length limitations in lookbehinds rang a bell when you mentioned it. When I
                Message 7 of 9 , Oct 11, 2009
                • 0 Attachment
                  flo.gehrke (flo.gehrke@...) wrote (in part) (on 2009-10-11 at
                  19:05):
                  > --- In ntb-clips@yahoogroups.com, Alec Burgess <buralex@...> wrote:
                  >
                  > > I've seen you (Sheri) and Flo use the \K construct before w/o
                  > > ever really understanding exactly how it worked.
                  > > Now that I know what the \K does, is there any difference between
                  > the
                  > > two (other than the simplicity of \K)
                  >
                  > Alec,
                  >
                  > As you you wrote, \K is similar to a Lookbehind Assertion. So
                  > (?<=Look)behind matches 'Lookbehind' without consuming the 'Look'.
                  > Look\Kbehind has the same effect.
                  >
                  > The difference is that the Lookbehind demands a fixed lenghth of the
                  > pattern whereas \K works with any length. That's why I often prefer
                  > \K.
                  >
                  > For example: (?<=\w+)behind produces an Error Message "Regex error:
                  > lookbehind assertion is not of fixed length." In contrast to that,
                  > \w+\Kbehind works fine.

                  Fixed length limitations in lookbehinds rang a bell when you mentioned
                  it. When I check with RegexBuddy I see that it fails with its (somewhat
                  old implementation of PCRE) but works with the JGSoft flavor (ie. Jan's
                  "superset" version of ALL regex flavors) and also with .NET flavor but
                  fails in most of the rest. For those that fail its indicated by marking
                  the "+" in RED.

                  I'm not sure if any future version of PCRE (and hence when supported by
                  Eric) Notetab will support this. I'll try to remember the key
                  distinction wrt. to \K when I write clips. Thanks for the followup info
                  (and Don for the question!).
                  //

                  --
                  Regards ... Alec (buralex@gmail & WinLiveMess - alec.m.burgess@skype)




                  [Non-text portions of this message have been removed]
                • Sheri
                  ... PCRE seeks backward from its bump-along starting point for a look-behind assertion. The fixed length requirement will never change; however it is
                  Message 8 of 9 , Oct 11, 2009
                  • 0 Attachment
                    Alec Burgess wrote:
                    > flo.gehrke (flo.gehrke@...) wrote (in part) (on 2009-10-11 at
                    > 19:05):
                    >
                    >> --- In ntb-clips@yahoogroups.com, Alec Burgess <buralex@...> wrote:
                    >>
                    >> > I've seen you (Sheri) and Flo use the \K construct before w/o
                    >> > ever really understanding exactly how it worked.
                    >> > Now that I know what the \K does, is there any difference between
                    >> the
                    >> > two (other than the simplicity of \K)
                    >>
                    >> Alec,
                    >>
                    >> As you you wrote, \K is similar to a Lookbehind Assertion. So
                    >> (?<=Look)behind matches 'Lookbehind' without consuming the 'Look'.
                    >> Look\Kbehind has the same effect.
                    >>
                    >> The difference is that the Lookbehind demands a fixed lenghth of the
                    >> pattern whereas \K works with any length. That's why I often prefer
                    >> \K.
                    >>
                    >> For example: (?<=\w+)behind produces an Error Message "Regex error:
                    >> lookbehind assertion is not of fixed length." In contrast to that,
                    >> \w+\Kbehind works fine.
                    >>
                    >
                    > Fixed length limitations in lookbehinds rang a bell when you mentioned
                    > it. When I check with RegexBuddy I see that it fails with its (somewhat
                    > old implementation of PCRE) but works with the JGSoft flavor (ie. Jan's
                    > "superset" version of ALL regex flavors) and also with .NET flavor but
                    > fails in most of the rest. For those that fail its indicated by marking
                    > the "+" in RED.
                    >
                    > I'm not sure if any future version of PCRE (and hence when supported by
                    > Eric) Notetab will support this. I'll try to remember the key
                    > distinction wrt. to \K when I write clips. Thanks for the followup info
                    > (and Don for the question!).
                    > //
                    >
                    >
                    PCRE seeks backward from its "bump-along" starting point for a
                    look-behind assertion.

                    The fixed length requirement will never change; however it is
                    permissible to have alternates of varying lengths within a look-behind.

                    In order to achieve the same match using \K instead of a look-behind
                    assertion, the bump-along position is at the beginning of the would-be
                    look-behind. So while the results are similar, the processing differs.

                    Regards,
                    Sheri
                  Your message has been successfully submitted and would be delivered to recipients shortly.