Every once in a while I need a little C# method to do some dirty work. Here is an example of how to use Regular Expressions to match Windows style filemask matching.

private bool FitsMask(string fileName, string fileMask)
{
string pattern =
‘^’ +
System.Text.RegularExpressions.Regex.Escape(fileMask.Replace(“.”, “__DOT__”)
.Replace(“*”, “__STAR__”)
.Replace(“?”, “__QM__”))
.Replace(“__DOT__”, “[.]”)
.Replace(“__STAR__”, “.*”)
.Replace(“__QM__”, “.”)
+ ‘$’;
return new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase).IsMatch(fileName);
}