it looks quite similar to PCRE syntax
Yes, many of the parameters to Apache directives do take regular expressions (regex) and the "flavour" of regex used is indeed PCRE.
This applies to mod_rewrite and in fact any other Apache module that uses regex.
There are some minor differences (and additions) in the syntax used by Apache, but this is primarily because there are no regex "delimiters" (commonly /
) to mark the start and end of the regex, so slashes do not need to be (backslash) escaped.
Also, because spaces are used as delimiters in Apache directives, literal spaces must be backslash escaped in the regex itself. Or, the regex can be surrounded in double quotes.
And since there are no regex delimiters, there are no pattern modifiers, such as i
(eg. /regex/i
) for case-insensitive matches. Instead, there are flags in mod_rewrite, eg. NC
(NOCASE
) for case-insensitive matches.
In addition to the normal syntax, you can prefix the pattern with !
to negate the regex. This makes it trivial to make a truthy expression when something does not match. mod_rewrite also has an additional backreference for matching groups in the RewriteCond
CondPattern ie. %1
as well $1
.
With Apache 2.4 you now have Apache Expressions, this does put back delimiters and pattern modifiers.