Re: Inverse grep

Paul Wankadia <>
Mon, 28 May 2012 07:50:26 -0700 (PDT)

          From comp.compilers

Related articles
Inverse grep (glen herrmannsfeldt) (2011-06-08)
Re: Inverse grep (Chris F Clark) (2011-06-12)
Re: Inverse grep (Tony Finch) (2011-06-13)
Re: Inverse grep (2011-06-14)
Re: Inverse grep (2011-06-15)
Re: Inverse grep (Paul Wankadia) (2012-05-28)
| List of all articles for this month |

From: Paul Wankadia <>
Newsgroups: comp.compilers
Date: Mon, 28 May 2012 07:50:26 -0700 (PDT)
Organization: Compilers Central
References: 11-06-015
Keywords: lex
Posted-Date: 28 May 2012 14:49:44 EDT

On Jun 9 2011, 9:01 am, glen herrmannsfeldt <>

> I suppose this is a strange question, but I was wondering if
> there was ever something like an inverse grep. That is,
> match a string against a file full of regular expressions.
> Now, one could just read the file, compile the regex one at
> a time, and do the match, but maybe there is another way.

The best way to match lots of regular expressions is not to match lots
of regular expressions. :)

In a nutshell, extract the fixed substrings of the regular
expressions, identify which of the fixed substrings (if any) are
present in the input string and determine which of the regular
expressions (if any) are worth trying to match.

The RE2 library includes this functionality, but you will need to BYO
Aho-Corasick implementation. Refer to

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.