Comment: skip match process when S exist, or remove optional left most target T, capture left and right part of T.
Use case: if N is not exist, modify/change T to N, or create N. If any create or modify write operated, appending output N to right.
skip exist:
^start of line
Negative Lookahead(?!.*S) .*any character (except for line terminators), repeated any number of times
Sthe literal S (8310 / 1238 / 5316) (case sensitive)
Comment:
captrue prefix :
^start of line
.*?any character (except for line terminators), repeated any number of times
Comment:
optional target to remove:
Non-Capturing Group(?:T|$) Tthe literal T (8410 / 1248 / 5416) (case sensitive)
Comment:
captrue postfix:
.*?any character (except for line terminators), repeated any number of times
$end of line
Comment:
Test string:
aa
aaT
Tcc
aaTcc
aaTbbTcc
aaS
aaTS
TccS
aaTccS
Saa
SaaT
STcc
SaaTcc
Substitution: $1$2N
Return:
aaN
aaN
ccN
aaccN
aabbTccN
aaS
aaTS
TccS
aaTccS
Saa
SaaT
STcc
SaaTcc
g modifier: global. Finds all matches instead of stopping after the first
m modifier: multiline. Causes ^ and $ to match the start and end of each line, not only the start and end of the string