It seems like your browser didn't download the required fonts. Please revise your security settings and try again.
Barracuda Campus Help Center / Reference

Regular Expressions

  • Last updated on

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.

Be careful when using special characters including |, *, '.' which are not taken literally unless escaped with a preceding backslash '\' character.


Operators recognized in regular expressions include:

*zero or more times
+one or more times
?zero or one time
( )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

one of the following characters:  a A c C


anything but the characters 'a', 'A', 'c', 'C'


letters 'a' through 'z' regardless of case


letters 'a' through 'z' or 'A' through 'Z' or a dot


any alphabetic character or a dash


digit, shortcut for [0-9]




part of word: shortcut for [A-Za-z0-9_]


non-word character


space character: shortcut for [ \n\r\t]
[^\s]non-space character

Miscellaneous Characters


beginning of line


end of line



word boundary


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:




matches cialis, but not specialist

p[^\w]?h[^\w]?a[^\w]?r[^\w]?m[^\w]?a[^\w]?c[^\w]?ymatches pha,rmacy or P.harm-acy

matches viagra, VIAGRA or vIaGRa


matches 1 or more digits: 0, 42, 007

(bad|good) matches the letters 'bad' or matches the letters 'good'
^freematches the letters 'free' at the beginning of a line

matches viagra or v1agra

v(ia|1a)gramatches viagRA or v1agra
v\|agramatches v|Agra, V|Agra, v|agRa, etc.
v(i|1|\|)?agramatches vagra, viaGra, v1agrA, V|AGRA, etc.

matches *FREE*, *frEE*, etc.

\*FREE\* V.*GRA matches *FREE* VIAGRA, *Free* VEHiCLegrA, etc.
http:\/\/matches http://