Formulating regular expressions
A regular expression is a pattern describing a certain amount of text. Before configuring a routing rule for a route, you should test the regular expressions using any of the testing engines available online to make sure you have constructed it correctly.
The table that follows describes the basic symbols used in regular expressions and their meanings; there are many tutorials on regular expressions available on the web (for example, the Zytrax.com "info" site, which also includes information on using submatches in your expressions).
Example expression | Description |
---|---|
[abc] | Match any character listed between brackets. In this case, a or b or c. |
[^abc] | Match any character except those listed between the brackets. In this case, any characters except a, b and c. |
X-X | A range is indicated by two characters (letters or digits) separated by a "-" sign and matches any element within the range, including the first character and the last character. One or more ranges can be specified inside the character class. For example:
|
. | Match any character except new-line |
\d | One digit from zero through nine, inclusive (equivalent to: [0-9]) |
\D | One non-numeric character |
\s | One whitespace character |
\S | One non-whitespace character |
\w | One word character |
\W | One non-word character |
X+ | Match the preceding element (X, in this case) one or more times |
X* | Match the preceding element (X, in this case) zero or more times |
X{n} | Match the preceding element (X, in this case) n times |
X{n,} | Match the preceding element (X, in this case) at least n times |
X{n,m} | Match the preceding element (X, in this case) at least n times, but no more than m times |
(abc)? Note: Matches "abc" or the empty string |
Parentheses indicate an optional match |
a|b Note: Matches "a" or "b" |
The | indicates choices (alternate matches) |