pepemosca wrote:In Keyword, why not to add \> to the end of the words that I want to exclude?
You can do that, but it is not necessary. It does not make a difference if \>
is used or not. The only difference would be that the search string is longer and therefore the search would be a little bit slower.
I don't have a deep insight to the Perl engine, but I think lookbehinds are applied from right the left. Let us simplify the expression to
/TGFindStr = "^[ \t]*(\u+)\>(?<!\<END\>)"
and think first how it works on the word ENDBOX. Most right character of found string is X. This character is compared with the negative lookbehind expression string which is simply the string END. X from ENDBOX is not equal D from END. So found string is surely okay. No further test necessary.
Now let us think about found string FEND with most right character is D. Most right character of negative lookbehind string is also D. So there is a match and therefore the next character to left must be analyzed. This is in both strings N, again a match, continue with next character to left, once again a match for E. Now when the lookbehind expression would be just (?<!END)" the negative lookbehind would return here true and FEND would be ignored. But the negative lookbehind expression is (?<!\<END). Therefore the Perl regex engine has to check now, if the E is the first character of the found string which is not the case or the character to the left is a non word character which is also not the case because F is a word character. Therefore the negative lookbehind is false for found string FEND and FEND is not excluded.
The search expression (\u+)\> finds only entire words and the negative lookbehinds are applied always from right to left on the found strings - from end of the words. The first character of the found string not matching the character at same position of the negative lookbehind string breaks further evaluation. Therefore \>
is not necessary on the lookbehind strings. This expression returns always true for all found strings here.