You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Bill Stoddard <bi...@wstoddard.com> on 2001/06/07 22:17:10 UTC
PCRE and regex question...
Is there a quick way I can check a string to see if it is a regex or not?
I am looking at extending SetEnvIf to accept a regex on the 'header' argument (value may
already be a regex). My first cut replaces this call in mod_setenvif:
val = apr_table_get(r->headers_in, b->name);
where b->name is a nonregex header name
with code that iterated through r->headers_in doing an ap_regex on each under the
assumption that b->name -may- be a regex. The problem with this is the unnecessary
performance hit on all requests when the b->name is NOT a regex (and where apr_table_get()
will do the right thing).
pcre_infofull() seems a likely candidate but it is not clear to me which field to check
Bill
Re: PCRE and regex question...
Posted by Joshua Slive <sl...@commerce.ubc.ca>.
On Thu, 7 Jun 2001, Greg Stein wrote:
> On Thu, Jun 07, 2001 at 05:01:16PM -0400, Greg Marr wrote:
> > At 04:17 PM 06/07/2001, Bill Stoddard wrote:
> > >Is there a quick way I can check a string to see if it is a regex or
> > >not? I am looking at extending SetEnvIf to accept a regex on the
> > >'header' argument (value may already be a regex).
> >
> > The absolute easiest would be to require that the regex start and end
> > with a /.
> > SetEnvIf nonregexheader
> > SetEnvIf /regexheader/
> >
> > You could also use a regex on it:
> > /^[-A-Za-z0-9_]*$/
> > This assumes that only letters, numbers, -, and _ are allowed in
> > header names.
>
> Strictly speaking, every string is a regex. It is just that "abc" doesn't
> say a whole lot :-)
>
> I like Greg Marr's suggestion of requiring /regex/. That also helps to
> clarify things for the user who is reading .conf.
>
I'll chime in here with my usual consistency arguments:
There are MANY Apache directives that take a regex and none of them
use the /regex/ notation. Please don't invent a new notation unless
it is really necessary.
I prefer Greg's second suggestion. Just evaluate the input at startup to
determine whether or not it is a regex and store the answer so that you
don't waste request-time processing.
Joshua.
Re: PCRE and regex question...
Posted by Greg Stein <gs...@lyra.org>.
On Thu, Jun 07, 2001 at 05:01:16PM -0400, Greg Marr wrote:
> At 04:17 PM 06/07/2001, Bill Stoddard wrote:
> >Is there a quick way I can check a string to see if it is a regex or
> >not? I am looking at extending SetEnvIf to accept a regex on the
> >'header' argument (value may already be a regex).
>
> The absolute easiest would be to require that the regex start and end
> with a /.
> SetEnvIf nonregexheader
> SetEnvIf /regexheader/
>
> You could also use a regex on it:
> /^[-A-Za-z0-9_]*$/
> This assumes that only letters, numbers, -, and _ are allowed in
> header names.
Strictly speaking, every string is a regex. It is just that "abc" doesn't
say a whole lot :-)
I like Greg Marr's suggestion of requiring /regex/. That also helps to
clarify things for the user who is reading .conf.
Cheers,
-g
--
Greg Stein, http://www.lyra.org/
Re: PCRE and regex question...
Posted by Bill Stoddard <bi...@wstoddard.com>.
> At 04:17 PM 06/07/2001, Bill Stoddard wrote:
> >Is there a quick way I can check a string to see if it is a regex or
> >not? I am looking at extending SetEnvIf to accept a regex on the
> >'header' argument (value may already be a regex).
>
> The absolute easiest would be to require that the regex start and end
> with a /.
> SetEnvIf nonregexheader
> SetEnvIf /regexheader/
>
> You could also use a regex on it:
> /^[-A-Za-z0-9_]*$/
> This assumes that only letters, numbers, -, and _ are allowed in
> header names.
>
For the sake of consistency, think I'll pursue option 2. Thanks.
Bill
Re: PCRE and regex question...
Posted by Greg Marr <gr...@alum.wpi.edu>.
At 04:17 PM 06/07/2001, Bill Stoddard wrote:
>Is there a quick way I can check a string to see if it is a regex or
>not? I am looking at extending SetEnvIf to accept a regex on the
>'header' argument (value may already be a regex).
The absolute easiest would be to require that the regex start and end
with a /.
SetEnvIf nonregexheader
SetEnvIf /regexheader/
You could also use a regex on it:
/^[-A-Za-z0-9_]*$/
This assumes that only letters, numbers, -, and _ are allowed in
header names.
--
Greg Marr
gregm@alum.wpi.edu
"We thought you were dead."
"I was, but I'm better now." - Sheridan, "The Summoning"