\\Root_Dir.*?(?!\.rep)'
Consider what the later part of this (after the .*?
) is asking for, at the same position in the string:
- Match single quote
- So not match
\.rep
clearly this will be true in the example because the .*?
with match .rep
and thus the negative look ahead is satisfied.
As .NET supports variable width look-arounds1, you need to perform the variable width part within the look ahead before separately performing it for the quote:
\\Root_Dir(?!.*?\.rep).*?'
However I would be tempted to break this up into:
- Starts with the prefix:
$value.StartsWith("\\Root_Dir")
- If #1 is true then use a regex with a negative loook behind:
(?<!\.rep)'$
(ie. a quote not preceeded by …).
1 No-one told the PM/dev others had concluded it was too hard.