The following examples illustrate the use and construction of simple regular expressions. Each example includes the type of text to match, one or more regular expressions that match that text, and notes that explain the use of the special characters and formatting.
- Match Exact Phrase Only
- Match Word or Phrase in a List
- Match Word with Different Spellings or Special Characters
- Match Any Email Address from a Specific Domain
- Match Any IP Address in a Range
- Match an Alphanumeric Format
For additional instructions and guidelines, see also Guidelines for using regular expressions and RE2 Syntax. See also Set up rules for content compliance.
Important: We support RE2 Syntax only, which differs slightly from PCRE. Regular expressions are case-sensitive by default.
Note: Examples shown below can be useful as starting points for morecomplex regular expressions. However, for matching a single word, we suggest that you use the Content compliance or Objectionable content settings.
Match Exact Phrase Only | |
---|---|
Usage example | Match the phrase stock tips. |
Regex examples | Example 1: (\W|^)stock\stips(\W|$) Example 2:(\W|^)stock\s{0,3}tips(\W|$) Example 3: (\W|^)stock\s{0,3}tip(s){0,1}(\W|$) |
Notes |
|
Match Word or Phrase in a List | |
---|---|
Usage example | Match any word or phrase in the following list:
|
Regex example | (?i)(\W|^)(baloney|darn|drat|fooey|gosh\sdarnit|heck)(\W|$) |
Notes |
|
Match Word with Different Spellings or Special Characters | |
---|---|
Usage example | Match the word viagra and some of the obfuscations that spammers use, such as:
|
Regex example | v[i!1][a@]gr[a@] |
Notes |
|
Match Any Email Address from a Specific Domain | |
---|---|
Usage example | Match any email address from the domains yahoo.com, hotmail.com, and gmail.com. |
Regex example | (\W|^)[\w.\-]{0,25}@(yahoo|hotmail|gmail)\.com(\W|$) |
Notes |
|
Match Any IP Address in a Range | |
---|---|
Usage example | Match any IP address within the range 192.168.1.0 to 192.168.1.255. |
Regex examples | Example 1: 192\.168\.1\. Example 2: 192\.168\.1\.\d{1,3} |
Notes |
|
Match an Alphanumeric Format | |
---|---|
Usage example | Match the purchase order numbers for your company. This number has various possible formats, such as:
|
Regex example | (\W|^)po[#\-]{0,1}\s{0,1}\d{2}[\s-]{0,1}\d{4}(\W|$) |
Notes |
|
Was this helpful?
How can we improve it?
Need more help?
Sign in for additional support options to quickly solve your issue
Sign in
Start your free 14-day trial today
Professional email, online storage, shared calendars, video meetings and more. Start your free Google Workspace trial today.