Hello, @francesco-vespari, @mkupper, @peterjones and all,
Here is my alternate solution :
SEARCH (?-is)^(?:(?!data).)+\R|(?:(?!data).)+|(database\.schema\.[A-Za-z]{3}[0-9]{3})
REPLACE ?1$1
This solution keeps any empty line which already exists in the present text :
So, for example, given this INPUT text :
SELECT *
FROM database.schema.ABC123
INNER JOIN database.schema.def456 on id1 = id2
LEFT JOIN database.schema.ghi789 on id2 = id3
WHERE 1=1
SELECT *
FROM database.schema.ABC123
INNER JOIN database.schema.def456 on id1 = id2
LEFT JOIN database.schema.ghi789 on id2 = id3
WHERE 1=1
SELECT *
FROM database.schema.ABC123
INNER JOIN database.schema.def456 on id1 = id2
LEFT JOIN database.schema.ghi789 on id2 = id3
WHERE 1=1
we would get this OUTPUT one :
database.schema.ABC123
database.schema.def456
database.schema.ghi789
database.schema.ABC123
database.schema.def456
database.schema.ghi789
database.schema.ABC123
database.schema.def456
database.schema.ghi789
Notes :
The first part of the search regex, after the modifiers (?-is) is ^(?:(?!data).)+\R which matches any complete line, with its line-break, ONLY IF it does NOT contain the string data, with this case, at any position of current line
The second alternative (?:(?!data).)+ matches any part of line, which does NOT contain the string data, with this case
Until now, just note that no group has been defined because of the two non-capturing syntaxes (?:...
Finally, the third alternative is the string that we want to keep, i.e. the string (database\.schema\.[A-Za-z]{3}[0-9]{3}), with this exact case, which is stored as group 1
As we use a conditional replacement ?1$1, which means : ONLY rewrite the group 1 if this group is defined, we are just left with the expected text !
Best Regards,
guy038