TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A Regular Expression Matcher (2007)

109 pointsby villeover 5 years ago

7 comments

dangover 5 years ago
A thread from 2016: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=12199836" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=12199836</a><p>2013: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=5672875" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=5672875</a><p>2011: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=2723366" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=2723366</a><p>Maybe others?<p>p.s. these links are just for curious readers; reposts are ok after a year or so—see <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;newsfaq.html" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;newsfaq.html</a>.
adriantamover 5 years ago
This is chapter 1 of &quot;Beautiful Code&quot; (<a href="http:&#x2F;&#x2F;shop.oreilly.com&#x2F;product&#x2F;9780596510046.do" rel="nofollow">http:&#x2F;&#x2F;shop.oreilly.com&#x2F;product&#x2F;9780596510046.do</a>)
评论 #22319280 未加载
glangdaleover 5 years ago
These posts are great for history, but regular expression implementation has moved on considerably from early Thompson implementations whether backtracking or NFAs. There is a considerable body of literature about regex implementation, including many quite convincing implementations and alternate formulations, some of which weren&#x27;t even done by people at, or from, Bell Labs!<p>We seem to have something of an Eternal September of regex implementation knowledge (abetted by Russ Cox&#x27;s amazingly selective bibliography in his posts introducing RE2).
hstaabover 5 years ago
I saw this in the repo of single file language implementations that was posted yesterday. Glad to see it on the front page now.<p>Here’s the repo if anyone is interested in checking out the others:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;marcpaq&#x2F;b1fipl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;marcpaq&#x2F;b1fipl</a>
jstimpfleover 5 years ago
Skimming over it, the implementation looks inefficient:<p><pre><code> int matchstar(int c, char *regexp, char *text) { do { &#x2F;* a * matches zero or more instances *&#x2F; if (matchhere(regexp, text)) return 1; } while (*text != &#x27;\0&#x27; &amp;&amp; (*text++ == c || c == &#x27;.&#x27;)); return 0; } </code></pre> That can be used to match short strings, but not to grep through a filesystem. A good regex matcher has runtime O(N*M) where N is the length of the regex (typically very short) and M is the length of the scanned text.
评论 #22322292 未加载
评论 #22326168 未加载
raverbashingover 5 years ago
Seeing code like this I can understand why the pioneers though C code could be pretty.<p>But now all I see there is something more akin to a demonstration of ice carving with chainsaws than something that should be used in a production system.
leohover 5 years ago
This would be a very good technical interview question — i.e. &quot;implement this simple regex specification.&quot;
评论 #22319670 未加载
评论 #22320963 未加载
评论 #22321566 未加载
评论 #22319332 未加载