Skip to content

Instantly share code, notes, and snippets.

@UweKeim
Last active January 28, 2024 21:32
Show Gist options
  • Save UweKeim/40f8b02de15f42fa256ce1edb46fbf33 to your computer and use it in GitHub Desktop.
Save UweKeim/40f8b02de15f42fa256ce1edb46fbf33 to your computer and use it in GitHub Desktop.
Convert wildcards to Regular Expressions.
private static string convertWildcardToRegex(string pattern)
{
// http://stackoverflow.com/a/6907849/107625
// http://www.codeproject.com/Articles/11556/Converting-Wildcards-to-Regexes
return "^" + Regex.Escape(pattern).
Replace("\\*", ".*").
Replace("\\?", ".") + "$";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment