Thursday, April 19, 2018

Match Item That Exists In A List Using Regular Expression and LINQ

Hi!
Using Any() in LINQ, we can match/find an item that exists in a List<T> or IEnumerable using Regular Expressions.
if(Products.Any(t => Regex.IsMatch(t, ProductsFromFrance.FrenchProdPattern))
{
   //true statement here..
}
Where Products is the List object and ProductsFromFrance.FrenchProdPattern is the Regular Expression pattern.

0 comments:

Post a Comment