Re: [pcre-dev] obtaining pattern from a compiled re

Top Page
Delete this message
Author: Giuseppe Attardi
Date:  
To: pcre-dev
Subject: Re: [pcre-dev] obtaining pattern from a compiled re
On 6/19/2010 10:33, Philip Hazel wrote:
> On Thu, 17 Jun 2010, Giuseppe Attardi wrote:
>
>
>> Is there a way to get back the original string pattern from a compiled pcre?
>>
> No. PCRE does not save the original string. It would be possible to
> write a function that generates an equivalent string, but it would not
> necessarily be the same as the original. For example, "a{0,}" might
> become "a*" and "a{0}" might be omitted altogether, "[abcd]" might be
> shown as "[a-d]". There are also optimizations: "a+b" would be shown as
> "a++b", for example, because PCRE optimizes it that way.
>

This would be fine, if recompiling the string I get the same pattern: I
need to serialize the pcre, so that I can reload it.
I know I could save the binary form using pcre_fullinfo, but a string is
preferable.

Thanks for the answer.

-- Beppe

> If you run the pcretest program with the -d option, it shows you a form
> of the compiled pattern, item by item, but not as a single string.
>
> Why do you want this?
>
> Philip
>
>