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

24349RE: [Clip] Advice to add 'Tabs' to data.

Expand Messages
  • John Shotsky
    Feb 14, 2014
    • 0 Attachment

      I wasn't explicit about how my variables are stored, but they are not stored with parens, only with vertical bars and \b where needed INSIDE the variable. Then, when used, I add the parens at use time. Often, I add extra words along with the variable inside the parens. I have thought about changing that, but so far have not found it to be better. Perhaps some more testing will show it as viable. So yes, it is captured, but is not replaced.

      I will try your suggestion though, as a learning exercise. I'm always open to learning better ways to do things.

      One of the things I have been doing is enclosing multiple paren phrases inside an (?= phrase), so that it won't capture, but I wonder if it is captured anyway.

      Replace ….(?= (this|that) (the other this|the other that).*$) Thoughts?

      Regards,
      John
      RecipeTools Web Site: http://recipetools.gotdns.com/
      John's Mags Yahoo Group:  http://groups.yahoo.com/group/johnsmags/

       

      From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of flo.gehrke@...
      Sent: Friday, February 14, 2014 09:03
      To: ntb-clips@yahoogroups.com
      Subject: RE: [Clip] Advice to add 'Tabs' to data.

       

       

      ---In ntb-clips@yahoogroups.com, <jshotsky@...> wrote:

      > For example, if I want the word 'cheese' to follow the word

      > Cheddar, but only want to insert it when it is missing, I use
      > this:
      >
      > ^!Replace "\b(^%Cheeses%)\b\K(?! cheese)" >> " cheese" AIRSW
      >
      > I store the names of the cheeses in a variable called
      > %Cheeses%. If it is determined that the name of a cheese is NOT
      > followed by the word cheese, it is inserted. Again, nothing is
      > captured, stored or replaced, only a word inserted in position
      > when missing.

      There's a misunderstanding in this statement. "The use of \K does not interfere with the setting of captured substrings (Help on RegEx)." So your subpattern '(^%Cheeses%)' will capture the match anyway. You can find this out with the test...

      ^!Set %Cheeses%=Cheddar
      ^!Find "\b(^%Cheeses%)\b\K(?! cheese)" RS
      ^!Info ^$GetReSubstrings$

      which will output 'Cheddar' where 'cheese' is missing.

      If we talk of superfluous capturings we should also mention superfluous parens. In your pattern, for example, there's no need to write '\b(^%Cheeses%)\b'. Writing '\b^%Cheese%\b' would work as well -- without capturing anything.

      If there is any need to group a subpattern you could avoid capturing by using a non-capturing group like '(?:^%Cheese%)'.

      Regards,
      Flo

    • Show all 18 messages in this topic