unicode

Pattern matching in C

Pattern matching using "*" and "?" wildcards is the common approach under Windows when it comes to comparing paths. Many applications - lead by DOS, cmd.exe and explorer.exe (the Windows Explorer) - allow users to use wildcards in paths. Users thereby are enabled to select a group of files matching specific criteria, which is often used in the "open document" dialog of Windows applications.

Matching a string agains a pattern is a very simple thing if you've got a framework or interpreted high level language like PHP or C# (or any of the .NET Framework languages). Those languages already provide classes or functions for using Regular Expressions (RegEx) and thus allow for very complex string comparison, string matching and string replacement features out of the box.

The same topic can become rather complicated when you're (for what reason ever) are limited to pure C and don't want or just can't include complex classes. As I had the same problem and luckily solved it, I decided to provide you the surprisingly very simple C code for matching a string against a pattern containing wildcard if you like.