A regular expression is a combination of characters or character classes and operators that describe text for matching purposes. Regular expressions are like wildcards, only more powerful. With Email Gateway Defense or the Barracuda Email Security Gateway, for example, you can use regular expressions in many of its block/allow features.
Note: Matches are not case-sensitive. All regular expressions are lowercase before use as is the text against which expressions are matched. For this reason, you cannot use capital letter character classes.
Operators
Operators recognized in regular expressions include:
* | zero or more times |
+ | one or more times |
? | zero or one time |
| | or |
( ) | grouping |
Character Classes
A character class matches a character or range of characters listed between brackets '[' and ']'. Use a dash '-' to specify a range of characters. Use the '^' character inside the brackets '[' and ']' to negate a class. Some examples are:
. | any character except newline |
[ac] | one of the following characters: a A c C |
[^ac] | anything but the characters 'a', 'A', 'c', 'C' |
[a-z] | letters 'a' through 'z' regardless of case |
[a-z.] | letters 'a' through 'z' or 'A' through 'Z' or a dot |
[a-z\-] | any alphabetic character or a dash |
\d | digit, shortcut for [0-9] |
[^\d] | non-digit |
\w | part of word: shortcut for [A-Za-z0-9_] |
[^\w] | non-word character |
\s | space character: shortcut for [ \n\r\t] |
[^\s] | non-space character |
Miscellaneous Characters
^ | beginning of line |
$ | end of line |
\b
| word boundary |
\t | tab character |
Special Characters
The following characters have a special meaning in regular expressions on Barracuda Email Gateway Defense and are prepended by a backslash '\' character when they are interpreted literally:
. | [ | ] | \ | * | ? | $ | ( | ) | | | ^ | @ | / |
Examples
\bcialis\b | matches cialis, but not specialist |
p[^\w]?h[^\w]?a[^\w]?r[^\w]?m[^\w]?a[^\w]?c[^\w]?y | matches pha,rmacy or P.harm-acy |
viagra | matches viagra, VIAGRA or vIaGRa |
\d+ | matches 1 or more digits: 0, 42, 007 |
(bad|good) | matches the letters 'bad' or matches the letters 'good' |
^free | matches the letters 'free' at the beginning of a line |
v[i1]agra | matches viagra or v1agra |
v(ia|1a)gra | matches viagRA or v1agra |
v\|agra | matches v|Agra, V|Agra, v|agRa, etc. |
v(i|1|\|)?agra | matches vagra, viaGra, v1agrA, V|AGRA, etc. |
\*FREE\* | matches *FREE*, *frEE*, etc. |
\*FREE\* V.*GRA | matches *FREE* VIAGRA, *Free* VEHiCLegrA, etc. |
http:\/\/ | matches http:// |