It can be checked whether a
word or phrase
is repeated in the given group of words
separated by ,
either using
LINQ
or
Regex
as shown below:
string words1 = "abcd,defgh xyz, abcd, defgh, abcd, abcd, ijkl";
string words2 = "abcd,defgh xyz, ijkl, mnop, qrst, uvw, abc, uvws, defghxyz";
int max = words1.Split(',').Select (w => w.Trim())
.GroupBy (w => w).Max (w => w.Count ());
Console.WriteLine (max);
bool result = Regex.IsMatch(words1,
@"(?:^\s*(?<word>[^,]+)\s*,|,\s*(?<word>[^,]+)\s*,)"+
@"(?=.*,\s*\k<word>\s*,|.*,\s*\k<word>\s*$)",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Console.WriteLine (result);
The regular expression can be tested here
http://regexhero.net/tester/[
^]