Groups | Search | Server Info | Login | Register


Groups > comp.compilers > #655

Re: Inverse grep

From Paul Wankadia <junyer@gmail.com>
Newsgroups comp.compilers
Subject Re: Inverse grep
Date 2012-05-28 07:50 -0700
Organization Compilers Central
Message-ID <12-05-026@comp.compilers> (permalink)
References <11-06-015@comp.compilers>

Show all headers | View raw


On Jun 9 2011, 9:01 am, glen herrmannsfeldt <gah@ugcs.caltech.edu>
wrote:

> 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 http://code.google.com/p/re2/source/browse/re2/filtered_re2.h.

Back to comp.compilers | Previous | Next | Find similar


Thread

Re: Inverse grep Paul Wankadia <junyer@gmail.com> - 2012-05-28 07:50 -0700

csiph-web