Last active
February 20, 2025 22:21
-
-
Save matthewnitschke/039c39c7f73c3c36be77 to your computer and use it in GitHub Desktop.
Simple wildcard matching in C#
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 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