Hi armaggadon,
Welcome to the DevShed regex board.
You bring a fantastic beginner question.
Here are some elements to help you understand what is going wrong.
1. [^CLTG] does not mean "not CLTG", but "any ONE character that is not a C, a L, a T or a G".
2. You probably have case-insensitive mode on? If so, on the second tag (TAG hello CLTG), the regex will fail on the first "l" in hello, as it is trying to match any one character that is not a L (or a c, t, or g).
3. Here is a way to match your entire tag:
Code:
TAG(?:[^C]|C(?!LTG))*CLTG
It matches TAG, then
any character that is NOT a C, OR a C that is not followed by LTG,
zero or more times,
then CLTG.
The (?! is a
negative lookahead from regex lookaround syntax.
You probably know that by adding parentheses, you could "capture" the text between TAG and CLTG, if for whatever reason you needed it later in your code or replacement.
Hope this helps, let me know if you have any questions!
Wishing you a fun weekend.
