httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Dessent <>
Subject Re: [users@httpd] Apache 1.3 mod_rewrite and regex backreferences
Date Thu, 22 Jan 2004 09:30:00 GMT
Olivier Poitrey wrote:

> > What  you're referring  to is  only valid  in the  "Perl compatible"
> > regular  expression flavor.   This is  not the  same as  egrep regex
> > flavor.  Apache 1.3 uses egrep,  2.0 uses pcre, if I'm not mistaken.
> > So you should be able to do this in 2.0 but not 1.3.
> I can read the following in the POSIX regex documentation:
> "[...] Finally, there  is one new type of atom,  a back reference: `\'
> followed by  a non-zero decimal digit  d matches the  same sequence of
> characters matched  by the dth  parenthesized subexpression (numbering
> subexpressions by the positions  of their opening parentheses, left to
> right),  so that  (e.g.)  `\([bc]\)\1'  matches `bb'  or `cc'  but not
> `bc'."
> And, if you test my regex with egrep, it works perfectly:
> $ echo "/foo/foo"|egrep '^/(foo)/\1'
> /foo/foo
> Finaly, I found in the  apache regex implementation source code (witch
> isn't the  same code as the  egrep regex engine as  you said), special
> things to handle  this kind of backreferences. In  can't bother why it
> doesn't work anyway.

Well, all I can say is that the POSIX specs for extended regexps seem to
be ambiguous.  The FreeBSD manpage (which is what I was looking at)
specifies that egrep doesn't support backreferences (but old-style basic
regexps do.)  If you consult
<> it says:

  .           Any single character
  [chars]     Character class: One  of chars
  [^chars]    Character class: None of chars
  text1|text2 Alternative: text1 or text2

  ?           0 or 1 of the preceding text
  *           0 or N of the preceding text (N > 0)
  +           1 or N of the preceding text (N > 1)

  (text)      Grouping of text
              (either to set the borders of an alternative or
              for making backreferences where the Nth group can 
              be used on the RHS of a RewriteRule with $N)

  ^           Start of line anchor
  $           End   of line anchor

  \char       escape that particular char
              (for instance to specify the chars ".[]()" etc.)

...that last part of which implies that \1 means the literal 1.  So, I
don't really know what to make of it.  Maybe one of the Apache
developers can give you a more specific response.  It does seem odd that
backreferences aren't working, though.


The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message