Skip to content

Instantly share code, notes, and snippets.

@matthewnitschke
Last active February 20, 2025 22:21
Show Gist options
  • Save matthewnitschke/039c39c7f73c3c36be77 to your computer and use it in GitHub Desktop.
Save matthewnitschke/039c39c7f73c3c36be77 to your computer and use it in GitHub Desktop.
Simple wildcard matching in C#
public bool MatchesPattern(string pattern, string text)
{
pattern = pattern.Replace("%", @".+");
pattern = pattern.Replace("_", @".");
Regex regex = new Regex(pattern);
if (regex.IsMatch(text))
{
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment