dcentre

The very basics of regexp

Escaping:

\char escape that particular char

For instance to specify special characters.. [].()\ etc.

Text:

. Any single character (on its own = the entire URI)
[chars] Character class: One of following chars
[^chars] Character class: None of following chars
text1|text2 Alternative: text1 or text2 (i.e. "or")

e.g. [^/] matches any character except /
(foo|bar)\.html matches foo.html and bar.html

Quantifiers:

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

e.g. (.+)\.html? matches foo.htm and foo.html
(foo)?bar\.html matches bar.html and foobar.html

Grouping:

(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 target of a RewriteRule with $n

e.g. ^(.*)\.html foo.php?bar=$1

Anchors:

^ Start of line anchor
$ End of line anchor

An anchor explicitly states that the character right next to it MUST
be either the very first character ("^"), or the very last character ("$")
of the URI string to match against the pattern, e.g..

^foo(.*) matches foo and foobar but not eggfoo
(.*)l$ matches fool and cool, but not foo

PoweredBy