Last active
December 26, 2015 19:59
-
-
Save jdmonty/7205438 to your computer and use it in GitHub Desktop.
c# string extension. I like 'like'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool Like(this string @string, string pattern, char wildcard = '%', bool ignoreCase = true) | |
{ | |
pattern = pattern.Replace(wildcard.ToString(), ".*"); | |
var options = RegexOptions.Singleline | RegexOptions.Compiled; | |
if (ignoreCase) options |= RegexOptions.IgnoreCase; | |
var regex = new Regex(pattern, options); | |
return regex.IsMatch(@string); | |
} |
Author
jdmonty
commented
Oct 28, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment