A Regular Expression Matcher in 30 lines of C
cs.princeton.edu
cs.princeton.edu
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.)
https://github.com/antirez/redis/blob/unstable/src/util.c#L1...
I use it in Redis, but in general being "glob matching" more standard compared to a regexp subset people are more likely to know the syntax.
Still nice to see that it can be done in so few lines.
I tried to make it short, but still somewhat readable, so it's not completely "golfed".
Wow, he pioneered that, too...