Hello @tommy-tan, @lycan-thrope, @mark-olson and All,
Given the INPUT text, below
SM1+VRDP4-OOCU4868933:20240906151200:;;::KOJ’ SM1+VRDP4 OOCU7704147:20240905132700:;;::KOJ’ SM1+VRDP4-CBHU4477056:20240906141100:;;::KOJ’ DEF456SM1+VRDP4-CBHU4477056:20240906141100:;;::KOJ’ AB9+VRDP4-CBHU4477056:20240906141100:;;::KOJ’A more simple formulation would be to use one of the three regexes, below :
(?-is)VRDP4.+?(?=:) which matches any string beginning by an uppercase string VRDP4 till the very first colon of the current line
(?-is)(?<=^SM1\+)VRDP4.+?(?=:) if, in addition, the uppercase string VRDP4 is preceded by an uppercase string SM1+, strictely beginning a line
(?-is)(?<=SM1\+)VRDP4.+?(?=:) if, in addition, the uppercase string VRDP4 is just preceded by an uppercase string SM1+
Now , if we consider the general example below :
ABC XYZ 123ABC XYZ ABCXYZ 123ABCXYZAs said above :
The regex (?-i)(?<=^ABC)XYZ would find any uppercase string XYZ if predeced by an uppercase string ABC strictely beginning a line
The regex (?-i)(?<=ABC)XYZ would find any uppercase string XYZ, if preceded by an uppercase string ABC
However the two regexes (?-i)^(?<=ABC)XYZ or (?-i)(?<=ABC)^XYZ cannot find any match ! Why ? Just because the ^ is a regex assertion which is a shorthand of the (?<=\n|\r) syntax. Thus, these two syntaxes can be replaced by (?-i)(?<=\n|\r)(?<=ABC)XYZ and (?-i)(?<=ABC)(?<=\n|\r)XYZ. And it obvious that the string XYZ CANNOT be preceded, at the same time, with both an EOL character and the string ABC !
For people who want to know the right syntaxes, in this specific case, they are (?s-i)^(?<=ABC..)XYZ and (?s-i)(?<=ABC..)^XYZ, where the two dots represent an EOL char ! So, they both match an uppercase string XYZ, right after an uppercase string ABC\r\n
Note that the third syntax (?s-i)(?<=ABC..)XYZ, without any ^ symbol, matches also the two uppercase strings XYZ, beginning a line
Actually, to be exhaustive, the later regex (?s-i)(?<=ABC..)XYZ matches any uppercase string XYZ, preceded by a fixed string of 5 characters :
The first three are the uppercase string ABC
The following two chars can be absolutely any char ( standard or EOL characters )
Best Regards,
guy038