It's very nice pattern-matching code, but it isn't a regular expression matcher. The class of patterns it's able to match is much smaller than the class of all regular expressions -- not because of missing "sugar" (character classes, +, non-greedy wildcards, ...) but because it doesn't support groups or the | operator.
As a result, the language supported by this matcher has, e.g., no way to match the pattern (ab)* or the pattern a|b. It's much, much less powerful than an actual regular expression matcher would be, and much of what makes it possible to do it in 30 lines of C is that loss of power.
(I've written extremely similar code before: this level of functionality -- basically, glob or DOS wildcards -- is pretty useful. I'm not Rob Pike, and my code for similar functionality would probably be longer than his. But my code, or even Rob Pike's code, for even the simplest thing that could honestly be called a regular expression matcher, would be longer than this by a bigger factor.)
That was a superb read. Given the author(s) (who I noticed only after reading), I suppose that's to be expected. I'd like to see a similarly elegant version that translates the RE to a DFA–if anyone has any suggestions, I'd be quite happy!
Yes, matching regular expressions is easy, if you don't care about speed or features. Like, being able to match a literal dot or asterisk. Or char classes, or getting case insensitivity right (like the German ß that matches SS, so case folding needs not to preserve string length).
Still nice to see that it can be done in so few lines.
As a result, the language supported by this matcher has, e.g., no way to match the pattern (ab)* or the pattern a|b. It's much, much less powerful than an actual regular expression matcher would be, and much of what makes it possible to do it in 30 lines of C is that loss of power.
(I've written extremely similar code before: this level of functionality -- basically, glob or DOS wildcards -- is pretty useful. I'm not Rob Pike, and my code for similar functionality would probably be longer than his. But my code, or even Rob Pike's code, for even the simplest thing that could honestly be called a regular expression matcher, would be longer than this by a bigger factor.)