Re: [pcre-dev] Feature suggestion: combine N compiled expres…

Página superior
Eliminar este mensaje
Autor: Zack Weinberg
Fecha:  
A: pcre-dev
Asunto: Re: [pcre-dev] Feature suggestion: combine N compiled expressions
On 10/26/07, Philip Hazel <ph10@???> wrote:
> On Thu, 25 Oct 2007, Zack Weinberg wrote:
> > I'm wondering how hard it would be to add a function to the PCRE
> > library that took an array of compiled regexps and combined them all
> > into one regexp, either by concatenation (abc) or alternation (a|b|c).
>
> Probably possible, but not totally straightforward (off the top of my
> head).


Thinking about it a bit more, a syntax-check-only mode for
pcre_compile2() would solve my problem just as well and might be
easier to implement?

> > My use for this is a file full of user-written regexps, whose ultimate
> > use is in a boolean "did any of these match this string?" decision -
> > so I currently have it coded to read the whole file and concatenate it
> > into one big long string with | between lines, then feed it to
> > pcre_compile2() all in one go. This makes it difficult to give good
> > diagnostics if there is a syntax error in a pattern. If I could
> > compile them all separately and then combine them afterward it would
> > be easier.
>
> I must be missing something. What is wrong with a loop that compiles and
> executes each one separately?


There are a lot of strings to be matched against; it's simpler to
combine the regexps than to store an array of pcre_t pointers. Also I
thought it might be faster this way.

zw