Let's try solving the problem in general case. Suppose we're given something like
select ...
where ... MyField like '%abc%'
we can try convert like expression into corresponding regular one:
Like | Description |Regular
-------------------------------------------------
_ | any character (one and only one) | .
% | any characters (zero or more) | .*
Implementation
// If you want to implement both "*" and "?"
private static String LikeToRegular(String value) {
return "^" + Regex.Escape(value).Replace("_", ".").Replace("%", ".*") + "$";
}
usage:
var result list
.Where(x => Regex.IsMatch(x.myTextColumn, LikeToRegular("%abc%")));
you may want to convert the data into string
before matching:
var result list
.Where(x => Regex.IsMatch(x.myDate.ToString(), LikeToRegular("%abc%")));