5 ms·
A Regular Expression Matcher (2007)
- adriantam 7y agoThis is chapter 1 of "Beautiful Code" (http://shop.oreilly.com/product/9780596510046.do http://shop.oreilly.com/product/9780596510046.do)
- drivers99 7y agoI thought I had seen it before. Verified you can actually see the whole chapter in a nicer (book vs web) layout in Amazon's "Look inside" feature since it's at the beginning of the book. https://www.amazon.com/Beautiful-Code-Leading-Programmers-Practice/dp/0596510047 https://www.amazon.com/Beautiful-Code-Leading-Programmers-Pr...
- hstaab 7y agoI saw this in the repo of single file language implementations that was posted yesterday. Glad to see it on the front page now. Here’s the repo if anyone is interested in checking out the others: https://github.com/marcpaq/b1fipl https://github.com/marcpaq/b1fipl
- deleted 7y ago[deleted]
- deleted 7y ago[deleted]
- deleted 7y ago[deleted]
- leoh 7y agoThis would be a very good technical interview question — i.e. "implement this simple regex specification."
- adambyrtek 7y agoI used to use this exact problem years ago when interviewing candidates at Google. At that time I thought it was a great question, but now I'm not that sure anymore if this approach to interviewing is the best way to assess candidates.
- leoh 7y agoSuper interesting. Could you say more? Perhaps it depends a bit on the role?
- elteto 7y agoWe software types must be masochists. It took Rob Pike an hour in the comfort of his private office to write this piece of code. How is this _at all_ like a typical software interview?
- dmos62 7y agoYou're right. At the same time, could it be interesting to see how someone approaches (not solves) an intimidating problem?
- reificator 7y agoAlso known as hazing.
- dekhn 7y agoThere's a common question, "convert an RE into an NFA" (https://en.wikipedia.org/wiki/Thompson%27s_construction https://en.wikipedia.org/wiki/Thompson%27s_construction)
- abecedarius 7y agoHave you seen that used for interviewing? Yes, some people can do it in a 1-hour interview, but wouldn't you rather ask something that can't be done from memory?
- raverbashing 7y agoSeeing code like this I can understand why the pioneers though C code could be pretty. 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.
- deleted 7y ago[deleted]
- dang 7y agoA thread from 2016: https://news.ycombinator.com/item?id=12199836 https://news.ycombinator.com/item?id=12199836 2013: https://news.ycombinator.com/item?id=5672875 https://news.ycombinator.com/item?id=5672875 2011: https://news.ycombinator.com/item?id=2723366 https://news.ycombinator.com/item?id=2723366 Maybe others? p.s. these links are just for curious readers; reposts are ok after a year or so—see https://news.ycombinator.com/newsfaq.html https://news.ycombinator.com/newsfaq.html.
- Gusen 7y agoPart II: Impeachment Is A Diversion And Delay - Blocking of the "impeachment" witnesses was collusion planned before the new year. Listen to an FBI agent's disclosure from Jan 1, 2O2O here. President was to resign late summer securing election for DNC. See latest updates. Here is the zip file, which was also made available in the 3Jan2O2O update. The file within is VID_20200101_201948.mp3. Turn up the volume and put on headphones. BB10Mp3Footage31Dec1Jan.zip 122.4mb https://drive.google.com/file/d/1IXOOhQhHybwky8Z5pGdr9ZXhWpIUazmi/view?usp=sharing https://drive.google.com/file/d/1IXOOhQhHybwky8Z5pGdr9ZXhWpI... The dialogue about the impeachment starts near the beginning. Having Biden in the White House is as good as Trump or anyone else in their organization. Obviously Schiff and Nadler pledged their allegiance to the organization by raping boys on the record, with their task being to drag out an impeachment designed to obstruct and delay any real efforts to remove the President, thus keeping Trump in power. The witness blocking was to cause an apparent uproar delaying things with legal actions until late Summer. Soon after, the President would resign, leaving any other candidate with not enough time or support to compete with an opportunistic Biden, who is as good as Trump or any other Illuminati friendly politician in the Presidency. 162 page PDF [last updated: February|4|2O2O]: https://drive.google.com/file/d/1S7T_kDv48E40eHzus6CTXHxcm0W2qxVc/view?usp=sharing https://drive.google.com/file/d/1S7T_kDv48E40eHzus6CTXHxcm0W... Previously reported: \Wag The Dog: first was feigned impeachment hearings meant to obstruct, now an attack on Iranians in Iraq. Here is what they are trying to distract from & cover up to retain power. $100+ billion in bribes to the highest offices in this country. 815+ deaths from child rapes to prove loyalty! See the latest PDF updates: FBI Director Wray, AG Barr, SoD Shanahan, & SoS Pompeo each raped boys and were paid billions in bribes for a Soros & Koch funded child rape org. So did Trump & his "impeachment" team Nadler,Schiff,Mueller.So did media moguls Redstone,Murdoch,Moonves. What are they trying to set up? Who can arrest them since they are all bribed and in on it ? Their strategy to stay in every office and obstruct until forced to leave no matter what. Feigning impeachment: see page 13O. erppmpoerwvfewq. ver verwbvoltwb. \\if;Download the video/audio file, put on headphones and turn up the volume. You will hear these people committing these crimes. Audio was broadcast into my apartment by outdated surveillance equipment illegally embedded within my walls. This very same technology was being used to broadcast me to the internet for five years without my consent. I own this footage. Please use this to prosecute all found within. Note:: I am obliviously speaking throughout the video, and it can be quite loud at times relative to the desired content. The are dozens more links, including these, that can be found in this PDF last updated 4 FEB 2O2O: https://drive.google.com/file/d/1S7T_kDv48E40eHzus6CTXHxcm0W2qxVc/view?usp=sharing https://drive.google.com/file/d/1S7T_kDv48E40eHzus6CTXHxcm0W... All members of the "Illuminati"; "....an underground organization of homosexuals and child rapists..." (from pg 26: Barack Obama with Jack Dorsey). President Donald Trump: Demands a $4 billion dollar bribe here at 10:18am 4thJan2019: 3JanCh3_900-1100.avi https://drive.google.com/file/d/1Grdr8xF2psKNsuYlEnl9dIRV-77YG0Vr/view?usp=sharing https://drive.google.com/file/d/1Grdr8xF2psKNsuYlEnl9dIRV-77... 3JanCh2_900-1100-avi https://drive.google.com/file/d/1LUmVygl_q0XVs8h2cWr8jZl-24fY0vBB/view?usp=sharing https://drive.google.com/file/d/1LUmVygl_q0XVs8h2cWr8jZl-24f... 3JanCh4_1000-1100.mp3 https://drive.google.com/file/d/1ZpP1pJbJakBgg-y-MWNozTxp3wJojHge/view?usp=sharing https://drive.google.com/file/d/1ZpP1pJbJakBgg-y-MWNozTxp3wJ... President Trump rapes and kills twelve boys, including five boys in a "who can rape five boys to death the fastest" game: 14JanCh3_600.mp3 https://drive.google.com/file/d/1ufPmglde9Mep0m6xYMJ9c4TWTjj258zB/view?usp=sharing https://drive.google.com/file/d/1ufPmglde9Mep0m6xYMJ9c4TWTjj... 14JanCh2_600-700.mp3 https://drive.google.com/file/d/136qLJdEn8eCs9tI4QtIxl4opW_Lw_gCF/view?usp=sharing https://drive.google.com/file/d/136qLJdEn8eCs9tI4QtIxl4opW_L... Speaker of the House Nancy Pelosi: Accepting a $3 billion dollar bribe at 1033 am on the 17 Jan 2019 to ensure Asian boys can get through the border at "Monterrey" undocumented to be raped: 17JanCh3_949-1100.avi https://drive.google.com/file/d/1eodHu4o5Cm3xEWhDqipSuTj-M1CZUvmE/view?usp=sharing https://drive.google.com/file/d/1eodHu4o5Cm3xEWhDqipSuTj-M1C... 17JanCh4_1017-1100.avi https://drive.google.com/file/d/1y-nWEQbempkVZSz230j9wTyduZNjDmnk/view?usp=sharing https://drive.google.com/file/d/1y-nWEQbempkVZSz230j9wTyduZN... Speaker Nancy Pelosi also "preps" boys with First Lady Melania Trump, defined as in she performs oral sex on the boys’ penis and anus, as a child rapist like Henry Porter would, while trying to remove fecal matter from the boy prior to handing them over to be raped and then subsequently murdered, for Supreme Court Justice Samuel Alito, who apparently decides he would rather just have ten billion dollars instead. US Attorney for Western New York James Kennedy rapes these boys instead: 12JanCh3_1533-1638.mp3 https://drive.google.com/file/d/1AgFkDsbPbI4b5Xd3Wbz2EVNNx25kW2Oz/view?usp=sharing https://drive.google.com/file/d/1AgFkDsbPbI4b5Xd3Wbz2EVNNx25... Attorney General William Barr with FBI Deputy Director Christopher Wray raped and killed boys for billions in bribes in Buffalo, NY on the 17Jan2019 at 7:50am: 18JanCh4_700mp3 https://drive.google.com/file/d/1UIdZkS5ZVksZdHYsnHk2t5losi0N0Bp7/view?usp=sharing https://drive.google.com/file/d/1UIdZkS5ZVksZdHYsnHk2t5losi0... 18JanCh2_700.mp3 gorepqkberqaoper,bqpo,rfbv. https://drive.google.com/file/d/1DFK8IAxm5pQVqZv9L518nfgP7_odB2Um/view?usp=sharing https://drive.google.com/file/d/1DFK8IAxm5pQVqZv9L518nfgP7_o... 18JanCh3_725-.mp3 https://drive.google.com/file/d/1DG5ej59Ic8RT9UhbyMdwT0BDcKIifGGm/view?usp=sharing https://drive.google.com/file/d/1DG5ej59Ic8RT9UhbyMdwT0BDcKI... Secretary of State Michael Pompeo and Secretary of Defense Patrick Shanahan each raped and killed boys on 5thJan'19 at 17:39 for billions in bribes: pxoimnerher;l,yt ,.tyey jnytr ntr/. 5JanCh3_1600 1800.mp3 https://drive.google.com/file/d/1ghgmNrQvJ8WfJ2TsDVx1ruDU36hrhx6S/view?usp=sharing https://drive.google.com/file/d/1ghgmNrQvJ8WfJ2TsDVx1ruDU36h... 5JanCh2_1721-1818.mp3 https://drive.google.com/file/d/1eSlD4otX4KZqWXboQM92Mu-6J02Mjwrg/view?usp=sharing https://drive.google.com/file/d/1eSlD4otX4KZqWXboQM92Mu-6J02... Leaders of the "impeachment" effort Jerrold Nadler, Robert Mueller, and Adam Schiff all rape and kill boys between 11:20pm and 1:10am: 14JanCh4_2300-0000.mp3 Nadler starts at about 20mins in- https://drive.google.com/file/d/1Kuvv2Zmbw5Jw7onbRI2hCZ0M8FU66GuU/view?usp=sharing https://drive.google.com/file/d/1Kuvv2Zmbw5Jw7onbRI2hCZ0M8FU... 14JanCh2_2304-2359.mp3 https://drive.google.com/file/d/1nofp5xF-aXXcCSgQVwj30KlzE9WLr1x1/view?usp=sharing https://drive.google.com/file/d/1nofp5xF-aXXcCSgQVwj30KlzE9W... Mueller at 12:25am, next is Schiff who starts 12:55-ish: 15JanCh2_000-100.mp3 https://drive.google.com/file/d/1EsmHfguwBuo2PbavJ1WYyhiML62tgCkj/view?usp=sharing https://drive.google.com/file/d/1EsmHfguwBuo2PbavJ1WYyhiML62... 15JanCh2_100-200.mp3 https://drive.google.com/file/d/1NZnWRnBryalNQu2yJmfJUdS2pA_rGSFH/view?usp=sharing https://drive.google.com/file/d/1NZnWRnBryalNQu2yJmfJUdS2pA_... 15JanCh4_000-100.mp3 https://drive.google.com/file/d/1ZEDJR6jb6ARpcNnWJTokBUKb2J2OQnwZ/view?usp=sharing https://drive.google.com/file/d/1ZEDJR6jb6ARpcNnWJTokBUKb2J2... 15JanCh4_100-200.mp3 https://drive.google.com/file/d/173aYWvWHH4VGht1h_2nM0IMdw746LeCL/view?usp=sharing https://drive.google.com/file/d/173aYWvWHH4VGht1h_2nM0IMdw74... Complete Media Protection: Lester Holt, of NBC NightlyNews, apparently a member of the Illuminati since the 1980's, along with ABC Nightly News lead anchor David Muir, stop over to the Porter studio in Buffalo, New York on 14Jan2019 at 5:00 am. They both rape and kill about two dozen boys by 6:00 am. Muir starts around 5.15am, then Holt about 5:38 am. Multi-billionaire Rupert Murdoch, owner of News Corp and also Fox Corporation, takes his turn after Holt. Video links below: 14JanCh3_500-601.avi zijnoijrpotmebr https://drive.google.com/file/d/1i7NKepeyG_FfdQRrM7KsnFOZOOX3o7UL/view?usp=sharing https://drive.google.com/file/d/1i7NKepeyG_FfdQRrM7KsnFOZOOX... 14JanCh2_530-600.avi https://drive.google.com/file/d/1NZzgN5ilI7ToroU5cfqMaL4o2u1RwidV/view?usp=sharing https://drive.google.com/file/d/1NZzgN5ilI7ToroU5cfqMaL4o2u1... Adding to the media protection and reason this is not picked up by the media, CBS and Viacom owner Sumner Redstone and Leslie Moonves rape and kill boys following the President. 14JanCh3_700.avi https://drive.google.com/file/d/10XDw6x3ldnnQiq7oIjpdYVENyXaB4aI0/view?usp=sharing https://drive.google.com/file/d/10XDw6x3ldnnQiq7oIjpdYVENyXa... 14JanCh2_700-800.avi https://drive.google.com/file/d/1NS_e6AzEZ05wnfljkGMETGU5CWYKfRDp/view?usp=sharing https://drive.google.com/file/d/1NS_e6AzEZ05wnfljkGMETGU5CWY... 161p PDF [last updated: Feb|4|2O2O]: https://drive.google.com/file/d/1S7T_kDv48E40eHzus6CTXHxcm0W2qxVc/view?usp=sharing https://drive.google.com/file/d/1S7T_kDv48E40eHzus6CTXHxcm0W... \\. Please repost in USA! Post gets censored in US Recently more relevant: From page 49, Senator Mitch McConnell: At 1632 Senator Mitch McConnell checks into the Porter camera system inquiring if he can be part of the "eviction" for $10 million dollars. He is informed by group members that there are enough people for the event already and his participation is not necessary. At 1634 McConnell states "I fucked 15 kids, how am I not getting paid by you?" He is dismissed by Donald Reeves with "I think that will be all Mr. McConnell." 13JanCh3_1600-1700.avi https://drive.google.com/file/d/1L7bqOpvaEWmLiJpMhJNQDrfsQAHtsX8-/view?usp=sharing https://drive.google.com/file/d/1L7bqOpvaEWmLiJpMhJNQDrfsQAH...
- glangdale 7y agoThese 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't even done by people at, or from, Bell Labs! We seem to have something of an Eternal September of regex implementation knowledge (abetted by Russ Cox's amazingly selective bibliography in his posts introducing RE2).
- jstimpfle 7y agoSkimming over it, the implementation looks inefficient: 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; } 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.
- ufo 7y agoA surprising number of regex tools used in the wild employ a backtracking algorithm like this one. Some popular features such as lookaheada, lookbehinds, and backreferences can't always be matched using a finite automaton.
- user2994cb 7y agoAn FSA matcher will be O(M) - one state transition per input character.
- jstimpfle 7y agoIf you're looking at a specific regex (~FSA), then N is constant... If you have a function that runs an arbitrary regex, then N will vary.