24349RE: [Clip] Advice to add 'Tabs' to data.
- Feb 14, 2014
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?
> For example, if I want the word 'cheese' to follow the word
> Cheddar, but only want to insert it when it is missing, I useThere'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...
> ^!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.
^!Find "\b(^%Cheeses%)\b\K(?! cheese)" RS
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%)'.
- << Previous post in topic Next post in topic >>