I\'m curious, does anybody know a good way to do regular expression matching in C? The only way I can think of is through Flex. Is this the only way or is there a better w
A completely different approach is to try a Parsing Expression Grammar (PEG). A PEG comes at the pattern matching problem from the point of view of a parser, and can even take advantage of multiple rules that form a complete grammar. That makes it possible to write expressions that match balanced parenthesis, which are otherwise quite difficult to express in most regexp dialects.
Although PEGs are relatively new, there should be a few implementations out there that are usable from C.
The PEG implementation I've personally used is LPeg. It is neatly bound to Lua, and coincidentally was written by one of Lua's principle authors, Roberto Ierusalimschy. It provides a complete PEG implementation, and also includes an adapter that translates a regexp into the equivalent PEG for execution.
Linking the Lua core to a C program just to get access to LPeg might sound like overkill, but it really wouldn't be that difficult to do, even if you had no plan to use Lua for other purposes.