I researched this and cannot figure out why ?! doesn't do a Not Equal in my code.
The code has this :
var policyOne = "C";
var policyTwo = "GF1";
var policyThree = "018"
string policyNumber = $"^(?!{Regex.Escape(policyOne)}){Regex.Escape(policyTwo)}{Regex.Escape(policyTwo)}$",
So while I have also tried ?!.* , I still cannot get it to recognize that the policyOne is NOT allowed to be "C"
All 3 of the variables are joined together in a sql linq where clause
I can provide more details if needed.
This is my code
string AnyStart = "XXXDEFGHI";
string AnythingMiddle = "ABCXXXGHI";
string AnyEnds = "ABCDEFZZZ";
List<string> Strings = new List<string>()
{
AnythingMiddle,
AnyStart,
AnyEnds
};
string hcdpPlnCvgCD = "ABC";
string HcdpPmtFctrCd = "DEF";
string hccCpmtFctrCd = "GHI";
var patterns = new string[]{
$"^(?!{Regex.Escape(hcdpPlnCvgCD)}){Regex.Escape(HcdpPmtFctrCd)}{Regex.Escape(hccCpmtFctrCd)}$",
$"^{Regex.Escape(hcdpPlnCvgCD)}(?!.*{Regex.Escape(HcdpPmtFctrCd)}){Regex.Escape(hccCpmtFctrCd)}$",
$"^{Regex.Escape(hcdpPlnCvgCD)}{Regex.Escape(HcdpPmtFctrCd)}(?!.*{Regex.Escape(hccCpmtFctrCd)})$",
};
var wildcards = new List<string>();
foreach (var pattern in patterns)
{
var matchResult = Strings.Where(s => Regex.IsMatch(s, pattern)).ToList();
matchResult.Dump();
}
wildcards.Dump();
policyTwodoes not start withpolicyOne. Why not just use^{Regex.Escape(policyTwo)}{Regex.Escape(policyTwo)}$?