private Regex GetFilter(String filter, Boolean matchWholeWord = false) { if (filter == null) { filter = String.Empty; } if (filter.Any(character => InvalidFilterCharacters.Contains(character))) { throw new ArgumentException("filter contains invalid characters"); } if (filter.Contains('/')) { filter = filter.Replace('/', '\\'); } var result = default(Regex); lock (FilterCache) { filter = Regex.Escape(filter).Replace("\\*", ".*").Replace("\\?", "."); if (matchWholeWord) { filter = "^" + filter + "$"; } if (!FilterCache.TryGetValue(filter, out result)) { FilterCache[filter] = result = new Regex(filter, RegexOptions.Compiled | RegexOptions.IgnoreCase); } } return(result); }