Regular Expression Syntax
Listed In Apache » Configuration — Viewing Full TutorialRegular expressions are used in many languages, but this tutorial is aimed at .htaccess. You can find use of it in Perl, PHP and C/C++. Regular Expressions (Regex) are used for searching, matching, replacing and so on using wildcards.
Regex is used in .htaccess for things such as mod_rewrite.
General Syntax
^ - start of a string. You need to begin with this with Regex in .htaccess.
$ - end of a string. If you're used to PHP and so on, forget this.
(.*) - wildcard
Conditionals etc..
. - single charachter
(x|y|z) - This is similar to boolean in PHP, it means x or y or z.
(...) - Grouped section
[hijkl] - Item in the range of h, i, j, k or l
[^abcd] - Item not in the range of a, b, c or d. For example: e.
!( - pattern - ) - should not occur. replace - pattern - with the rule, e.g !((x|y|z)) means x y or z mustn't occur in the string
Counting occurences
x? - 0 or 1 of x / These two are pretty useless, but I'll include them anyway
a* - 0 or more of a. |
a+ - 1 or more of a.
x{3} - exactly 3 of x
x{4,} 4 or more of x
x{1,3} 1 to 3 of x
