[ad_1]
I would like to know how to implement Regex on the two words “co-confidential” , “confidential” and normal words?
I did the following, but when it checks for “confidential”, even the text with “co-confidential” on it also were being discovered. “Source” is the text that is being searched. “toCheck” is the keyword string that I am searching for.
public static bool Validate_Text( this string source, string toCheck)
{
//if either strings are null or empty
if (string.IsNullOrEmpty(toCheck) || string.IsNullOrEmpty(source))
{
return false;
}
if (Regex.IsMatch(source, @"\b" + toCheck + @"\b", RegexOptions.Singleline | RegexOptions.IgnoreCase))
{
return true;
}
else if (Regex.IsMatch(source, @"[^a-zA-Z0-9-]" + toCheck + @"[^a-zA-Z0-9]", RegexOptions.Singleline | RegexOptions.IgnoreCase))
{
return true;
}
else
return false;
}
[ad_2]