HN Hall of Fame Weekly email

A Regular Expression Matcher (2007)

www.cs.princeton.edu Books & learning Tutorials & guides Computer science Candidate
Screenshot of www.cs.princeton.edu captured 2026-07-20
Page preview · captured 2026-07-20

Resurfaced independently across 9 calendar years, with breakout response in 2 of them.

submissions
10
submitters
10
observed span
2011–2024
peak thread · 45 comments
132 pts
latest 20+ return · 2022-08-25
85 pts

Submission timeline

2007–2026

One slot for every year since HN launched. Height is that year's peak points; orange marks a 100+ point or 50+ comment breakout. Select a bar to open its strongest thread.

First comments on top threads

HN comment order

I have a re.c file in my best-of collection of code examples locally - but I can't seem to find the original source quickly - nevertheless it was written by Russ Cox[0] and he's spent a lot of time making regular expressions accessible and elegant, his articles are a great resource. [0] https://swtch.com/~rsc/regexp/

Can someone explain to me why the matchstar function takes its first param as an integer? to me it should be a char. int matchstar(int c, char *regexp, char *text) { do { /* a * matches zero or more instances */ if (matchhere(regexp, text)) return 1; } while (*text != '\0' && (*text++ == c || c == '.')); return 0; }

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…

gjm11·63-point thread·

"[star] matches zero or more occurrences of the previous character" …those aren't regular expressions. Those are fancy globs. Regular expressions have a formal definition that is strictly more expressive than that. They mention they use recursion (which you can use to actually implement regular expressions, albeit poorly) but… …they use the recursion as a way of implementing a state machine in C? You can get away with this (and it's somewhat common) in a language like Lisp or ML that…

The first top-level comment from each of the four biggest threads, in HN’s own order. Excerpts are shortened; open a comment for full context.

Breakout years
2

100+ points or 50+ comments

Total points
507

reference only — not used in Hall rules or ranking

Total comments
137

reference only — not used in Hall rules or ranking

Every submission

DateTitle as submittedByPointsComments
2011-07-03A Regular Expression Matcher in 30 lines of Ccoderdude639
2012-04-11A [beautiful] Regular Expression Matcherwickedchicken40
2013-05-08A regular expression matcher By Rob Pike and Brian Kernighan (2007)sid63769645
2015-12-01A Regular Expression Matcher (2007)sagargv121
2016-08-01A Regular Expression Matcher (2007)First breakout · Best thread_acme13234
2018-02-09A Regular Expression Matchershakkhar20
2020-02-13A Regular Expression Matcher (2007)ville10922
2022-03-26A Regular Expression Matcher by Rob Pikewazbug20
2022-08-25A Regular Expression Matcher (2007)Latest 20+ point returnsynergy208525
2024-05-23A Regular Expression Matcher (2007)aragonite21