Re: [pcre-dev] ability to name a regexp and reuse it in anot…

Pàgina inicial
Delete this message
Autor: Philippe Strauss
Data:  
A: pcre-dev
Assumpte: Re: [pcre-dev] ability to name a regexp and reuse it in another one
Yes, but I'm not using perl, but PCRE (mostyl on ocaml).

This qr// perl operator doesn't need any support from the regexp backend ?

Is it just string interpolation with a syntax sugar ? I was thinking of a compiled form of the sub-regexp, reusable in a similar manner thant qr// allows.

I guess the compiled form needs support from PCRE, and the other way is plain simple string interpolation (which can be acceptable depending on the situations, but may not simplify your code overall on other situations).


Regards.

Le 17 févr. 2012 à 17:02, Richard COOK a écrit :

> On Feb 16, 2012, at 5:13 AM, Philippe Strauss wrote:
>
>> Hello PCRE developpers,
>>
>> I find myself the last few days writing pcre regexp like :
>>
>> "^([\\p{Latin}\\-]+)\\s(?i:v|var)(?::|\\.|\\s)\\s?([\\p{Latin}\\-]+)\\s(?i:f|forme)(?::|\\.|\\s)\\s?([\\p{Latin}\\-]+)$"
>>
>> the double backslash beeing a thing of the String module of the host language, ocaml here.
>>
>> Is there any plan to add a feature enabling the user to name a part of a regexp like :
>>
>> [\p{Latin}\-]+
>>
>> (which is just a souped up \w+)
>>
>> and reuse it later, would allow more readable writing of long regexp.
>> (in that particular case, the naming could be \w, redifining \w)
>>
>> would be a really nice feature !
>>
>> Note that I'm subscribing to this list just to ask about this, sorry if it's an FAQ.
>
> You probably want to use something like Perl's qr// operator, i.e. something like
>
>     my $r = qr/^your regex here$/i;

>
> Put that in an eval block to check for regex compile-time errors ...
>
> Note also that Perl's \p{CustomCharClassName} mechanism can be combined with this.
>
> This is described in Perl documentation; and other languages may have similar functionality.
>
> So, my guess is that pcre-dev list might not be the right place to request this feature ...
>
> -Richard


--
Philippe Strauss
http://www.strauss-acoustics.ch/