You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@httpd.apache.org by Rich Bowen <rb...@rcbowen.com> on 2001/08/23 04:43:58 UTC

Regular Expressions

Is there any treatment, anywhere in the Apache documentation, of what
flavor of regular expressions are supported by Apache directives? I
can't find it, but perhaps I'm just overlooking it, and will find it
as soon as I send this.

It would be nice to have at least a pointer to a regular expression
tutorial, and perhaps a description of some kind in the docs
themselves about what type of regular expressions these are, what
things are permitted in them, and how to do things like
case-insensitive patterns, character classes, variable capture (the
$1, $2 stuff) and all those sorts of nifty things. If someone can
point me in the right direction, I'd be glad to get such a thing
started.

Thanks

-- 
Rich Bowen - rbowen@rcbowen.com
As we trace our own few circles around the sun
We get it backwards and our seven years go by like one
	Dog Years (Rush - Test for Echo - 1999)


---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Rich Bowen <rb...@rcbowen.com>.
On Thu, 23 Aug 2001, Thomas Eibner wrote:

> On Wed, Aug 22, 2001 at 10:43:58PM -0400, Rich Bowen wrote:
> > Is there any treatment, anywhere in the Apache documentation, of what
> > flavor of regular expressions are supported by Apache directives? I
> > can't find it, but perhaps I'm just overlooking it, and will find it
> > as soon as I send this.
> >
> > It would be nice to have at least a pointer to a regular expression
> > tutorial, and perhaps a description of some kind in the docs
> > themselves about what type of regular expressions these are, what
> > things are permitted in them, and how to do things like
> > case-insensitive patterns, character classes, variable capture (the
> > $1, $2 stuff) and all those sorts of nifty things. If someone can
> > point me in the right direction, I'd be glad to get such a thing
> > started.
>
> You aren't thinking of the mod_rewrite [1] stuff are you?
>
> [1] http://httpd.apache.org/docs/mod/mod_rewrite.html

Well, perhaps. The mod_rewrite docs have a very brief synopsis of
regex syntax, and even go as far as to state that it uses POSIX regex,
which is much more specific than I have found elsewhere. But even the
synopsis there leaves out parts of the regex syntax.

With the number of modules that have some variety of FooMatch directive,
I think that it's important to have a document which all of these
module docs can point to which discusses the breed of regex supported
in Apache (apparently it's POSIX) and what syntax is available. Now
that I have somewhere to start, I'll go ahead and write such a beast,
and then we can figure out where it should to in the scheme of things.

Thanks for the pointer. I expected something in the mod_rewrite docs,
but did not stumble across anything right away.

-- 
Rich Bowen - rbowen@rcbowen.com
... and another brother out of his mind, and another brother out at New
York (not the same, though it might appear so)
	Somebody's Luggage (Charles Dickens)


---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Thomas Eibner <th...@stderr.net>.
On Wed, Aug 22, 2001 at 10:43:58PM -0400, Rich Bowen wrote:
> Is there any treatment, anywhere in the Apache documentation, of what
> flavor of regular expressions are supported by Apache directives? I
> can't find it, but perhaps I'm just overlooking it, and will find it
> as soon as I send this.
> 
> It would be nice to have at least a pointer to a regular expression
> tutorial, and perhaps a description of some kind in the docs
> themselves about what type of regular expressions these are, what
> things are permitted in them, and how to do things like
> case-insensitive patterns, character classes, variable capture (the
> $1, $2 stuff) and all those sorts of nifty things. If someone can
> point me in the right direction, I'd be glad to get such a thing
> started.

You aren't thinking of the mod_rewrite [1] stuff are you?

[1] http://httpd.apache.org/docs/mod/mod_rewrite.html

-- 
  Thomas Eibner <http://thomas.eibner.dk/> DnsZone <http://dnszone.org/>
  mod_pointer <http://stderr.net/mod_pointer> 


---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Rich Bowen <rb...@rcbowen.com>.
On Thu, 23 Aug 2001, Thomas Eibner wrote:

> On Wed, Aug 22, 2001 at 11:15:12PM -0400, Rich Bowen wrote:
> >
> > No, the / character does not have special meaning in these regular
> > expressions. More specifically, there is no delimiter, as there is in
> > Perl. You just have a string, and that is the regex. Perl has a
> > character that indicates the start and end of the pattern. While this
> > is traditionally / it can be anything. But, since there is no such
> > character used, you can't put switches like Perl's /i or /s or
> > whatever on the end after the closing delimiter.
> >
> > egrep is the same way (same as apache that is) in that you just
> > provide a string
> >
> > egrep "patt?[eu]rn" file.name
> >
> > The quotes are optional if the pattern does not contain any special
> > characters.
>
> But where excactly are you using/needing this?

At this exact moment, I am looking at AliasMatch and ScriptAliasMatch.
However, a pretty large number of modules have a SomethingMatch
directive which accepts a regex as an argument.

BrowserMatch
FilesMatch
LocationMatch
DirectoryMatch

and so on.

-- 
Rich Bowen - rbowen@rcbowen.com
Author - Apache Server Unleashed - http://www.apacheunleashed.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Thomas Eibner <th...@stderr.net>.
On Wed, Aug 22, 2001 at 11:15:12PM -0400, Rich Bowen wrote:
> 
> No, the / character does not have special meaning in these regular
> expressions. More specifically, there is no delimiter, as there is in
> Perl. You just have a string, and that is the regex. Perl has a
> character that indicates the start and end of the pattern. While this
> is traditionally / it can be anything. But, since there is no such
> character used, you can't put switches like Perl's /i or /s or
> whatever on the end after the closing delimiter.
> 
> egrep is the same way (same as apache that is) in that you just
> provide a string
> 
> egrep "patt?[eu]rn" file.name
> 
> The quotes are optional if the pattern does not contain any special
> characters.

But where excactly are you using/needing this? 

-- 
  Thomas Eibner <http://thomas.eibner.dk/> DnsZone <http://dnszone.org/>
  mod_pointer <http://stderr.net/mod_pointer> 


---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Rich Bowen <rb...@rcbowen.com>.
On Thu, 23 Aug 2001, Thomas Eibner wrote:

> On Wed, Aug 22, 2001 at 10:59:27PM -0400, Rich Bowen wrote:
> > On Wed, 22 Aug 2001, Rich Bowen wrote:
> >
> > > Is there any treatment, anywhere in the Apache documentation, of what
> > > flavor of regular expressions are supported by Apache directives? I
> > > can't find it, but perhaps I'm just overlooking it, and will find it
> > > as soon as I send this.
> >
> > OK, so immediately after I sent this, I found the following in
> > mod_include.html:
> >
> > Regular expressions have the same syntax as those found in the Unix
> > egrep command.
> >
> > This is, as far as I can find so far, the only specific explanation of
> > what regex syntax Apache supports.
> >
> > FAQ-B states that "We implement a simple subset of Perl's regex
> > support" which is pretty darned vague.
> >
> > man egrep has a really good regex explanation. The only question I'm
> > left with is how to get it to do case-insensitive pattern matching,
> > since egrep does this with a command line switch (-i) rather than in
> > the regex itself.
>
> I take it /i doesn't work, right? (Which of course is what you'd use in
> perl)

No, the / character does not have special meaning in these regular
expressions. More specifically, there is no delimiter, as there is in
Perl. You just have a string, and that is the regex. Perl has a
character that indicates the start and end of the pattern. While this
is traditionally / it can be anything. But, since there is no such
character used, you can't put switches like Perl's /i or /s or
whatever on the end after the closing delimiter.

egrep is the same way (same as apache that is) in that you just
provide a string

egrep "patt?[eu]rn" file.name

The quotes are optional if the pattern does not contain any special
characters.

-- 
Who can say where the road goes
Where the day flows
Only time
 --Pilgrim (Enya - A Day Without Rain)


---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Thomas Eibner <th...@stderr.net>.
On Wed, Aug 22, 2001 at 10:59:27PM -0400, Rich Bowen wrote:
> On Wed, 22 Aug 2001, Rich Bowen wrote:
> 
> > Is there any treatment, anywhere in the Apache documentation, of what
> > flavor of regular expressions are supported by Apache directives? I
> > can't find it, but perhaps I'm just overlooking it, and will find it
> > as soon as I send this.
> 
> OK, so immediately after I sent this, I found the following in
> mod_include.html:
> 
> Regular expressions have the same syntax as those found in the Unix
> egrep command.
> 
> This is, as far as I can find so far, the only specific explanation of
> what regex syntax Apache supports.
> 
> FAQ-B states that "We implement a simple subset of Perl's regex
> support" which is pretty darned vague.
> 
> man egrep has a really good regex explanation. The only question I'm
> left with is how to get it to do case-insensitive pattern matching,
> since egrep does this with a command line switch (-i) rather than in
> the regex itself.

I take it /i doesn't work, right? (Which of course is what you'd use in
perl)

-- 
  Thomas Eibner <http://thomas.eibner.dk/> DnsZone <http://dnszone.org/>
  mod_pointer <http://stderr.net/mod_pointer> 


---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Cliff Woolley <cl...@yahoo.com>.
On Wed, 22 Aug 2001, Rich Bowen wrote:

> case-insensitive patterns,

With pcre, you should be able to put (?i) at the beginning of the pattern
(see perlre manpage).  Not sure if hsregex supports that.

> character classes,

Those are fine... just the usual [abcde] syntax.

> variable capture (the
> $1, $2 stuff) and all those sorts of nifty things.

AFAIK, of the standard modules that allow regex's in config file
directives, only mod_rewrite uses backreferences.  The rewriteguide does a
good job of explaining their use there.

--Cliff

--------------------------------------------------------------
   Cliff Woolley
   cliffwoolley@yahoo.com
   Charlottesville, VA



---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Rich Bowen <rb...@rcbowen.com>.
On Fri, 24 Aug 2001, Joshua Slive wrote:

>
> On Wed, 22 Aug 2001, Rich Bowen wrote:
>
> > It would be nice to have at least a pointer to a regular expression
> > tutorial, and perhaps a description of some kind in the docs
> > themselves about what type of regular expressions these are, what
> > things are permitted in them, and how to do things like
> > case-insensitive patterns, character classes, variable capture (the
> > $1, $2 stuff) and all those sorts of nifty things. If someone can
> > point me in the right direction, I'd be glad to get such a thing
> > started.
>
> For what it's worth, I support a short doc (in misc/) that exaplains
> what a regular expression is and where to get more information;
> perhaps a few examples could be included.  Alternatively,
> an improved FAQ answer would be nice.

OK, I missed that. I'll look at that this weekend. Thanks.

-- 
Who can say where the road goes
Where the day flows
Only time
 --Pilgrim (Enya - A Day Without Rain)


---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Joshua Slive <jo...@slive.ca>.
On Wed, 22 Aug 2001, Rich Bowen wrote:

> It would be nice to have at least a pointer to a regular expression
> tutorial, and perhaps a description of some kind in the docs
> themselves about what type of regular expressions these are, what
> things are permitted in them, and how to do things like
> case-insensitive patterns, character classes, variable capture (the
> $1, $2 stuff) and all those sorts of nifty things. If someone can
> point me in the right direction, I'd be glad to get such a thing
> started.

For what it's worth, I support a short doc (in misc/) that exaplains
what a regular expression is and where to get more information;
perhaps a few examples could be included.  Alternatively,
an improved FAQ answer would be nice.

Joshua.


---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Rich Bowen <rb...@rcbowen.com>.
On Wed, 22 Aug 2001, Cliff Woolley wrote:

> On Wed, 22 Aug 2001, Rich Bowen wrote:
>
> > Regular expressions have the same syntax as those found in the Unix
> > egrep command.
> >
> > This is, as far as I can find so far, the only specific explanation of
> > what regex syntax Apache supports.
> >
> > FAQ-B states that "We implement a simple subset of Perl's regex
> > support" which is pretty darned vague.
>
> Well, Apache 1.3 comes with hsregex, but you're allowed to use your OS's
> regex library if you want.  Assuming we're talking about hsregex, you can
> find man pages for it in apache-1.3/src/regex (the files regex.3 and
> regex.7).  Apache 2.0 switched to PCRE (Perl Compatible Regular
> Expressions) and IIRC it does not support using the OS regex library at
> this time.  The name on this one kind of says it all, but you can find
> more details at www.pcre.org.  Since they're Perl compatible, the best
> reference IMO is the perlre manpage.

Yes, thanks. That helps a great deal.

-- 
Rich Bowen - rbowen@rcbowen.com
ReefKnot - http://www.reefknot.org


---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Cliff Woolley <cl...@yahoo.com>.
On Wed, 22 Aug 2001, Rich Bowen wrote:

> Regular expressions have the same syntax as those found in the Unix
> egrep command.
>
> This is, as far as I can find so far, the only specific explanation of
> what regex syntax Apache supports.
>
> FAQ-B states that "We implement a simple subset of Perl's regex
> support" which is pretty darned vague.

Well, Apache 1.3 comes with hsregex, but you're allowed to use your OS's
regex library if you want.  Assuming we're talking about hsregex, you can
find man pages for it in apache-1.3/src/regex (the files regex.3 and
regex.7).  Apache 2.0 switched to PCRE (Perl Compatible Regular
Expressions) and IIRC it does not support using the OS regex library at
this time.  The name on this one kind of says it all, but you can find
more details at www.pcre.org.  Since they're Perl compatible, the best
reference IMO is the perlre manpage.

Hope this helps.

--Cliff

--------------------------------------------------------------
   Cliff Woolley
   cliffwoolley@yahoo.com
   Charlottesville, VA





---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org


Re: Regular Expressions

Posted by Rich Bowen <rb...@rcbowen.com>.
On Wed, 22 Aug 2001, Rich Bowen wrote:

> Is there any treatment, anywhere in the Apache documentation, of what
> flavor of regular expressions are supported by Apache directives? I
> can't find it, but perhaps I'm just overlooking it, and will find it
> as soon as I send this.

OK, so immediately after I sent this, I found the following in
mod_include.html:

Regular expressions have the same syntax as those found in the Unix
egrep command.

This is, as far as I can find so far, the only specific explanation of
what regex syntax Apache supports.

FAQ-B states that "We implement a simple subset of Perl's regex
support" which is pretty darned vague.

man egrep has a really good regex explanation. The only question I'm
left with is how to get it to do case-insensitive pattern matching,
since egrep does this with a command line switch (-i) rather than in
the regex itself.

-- 
Nothing is perfekt. Certainly not me.
Success to failure. Just a matter of degrees.


---------------------------------------------------------------------
To unsubscribe, e-mail: apache-docs-unsubscribe@apache.org
For additional commands, e-mail: apache-docs-help@apache.org