I’m looking for simple and powerful way to implement Windows flavoured * and ? wildcards matching in strings.
BeginsWith(), EndsWith() too simple to cover all cases, while translating wildcards expressions to regex’es will look to complex and I’m not sure about performance.
A happy medium wanted.
EDIT: I’m trying to parse .gitignore file and match the same files, as Git does. This means:
- File should be out of repository’s index (so I’m checking file’s path against one stored in index)
- Number of patterns in
.gitignorecan be large; - Number of files to check might also be large.
The equivalents of the Windows wildcards
?and*in regex are just.and.*.[Edit] Given your new edit (stating that you’re looking for actual files), I would skip the translation altogether and let .Net do the searching using
Directory.GetFiles().(note that, for some reason, passing a
?intoDirectory.GetFiles()matches “zero or one characters,” whereas in Windows it always matches exactly one character)