How to write regular expressions
This topic describes the matching rules for regular expressions.
Only RE2 syntax is supported. This syntax is slightly different from PCRE. Note that regular expressions are case-sensitive by default. For more information, see the RE2 syntax.
Match only exact phrases | |
Usage example | Match the phrase stock tips |
Regex example | 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 words or phrases in a list | |
Usage example | Match any word or phrase from the following list:
|
Regex example | (?i)(\W|^)(baloney|darn|drat|fooey|gosh\sdarnit|heck)(\W|$) |
Notes |
|
Match words with different spellings or special characters | |
Usage example | Match the word "viagra" and some variations used by spam senders, such as:
|
Regex example | v[i!1][a@]gr[a@] |
Notes |
|
Match all email addresses 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 all IP addresses in a range | |
Usage example | Match all IP addresses in the range from 192.168.1.0 to 192.168.1.255 |
Regex example | Example 1: 192\.168\.1\. Example 2: 192\.168\.1\.\d{1,3} |
Notes |
|
Match alphanumeric formats | |
Usage example | Match a company's purchase order numbers. These numbers can have various formats, such as:
|
Regex example | (\W|^)po[#\-]{0,1}\s{0,1}\d{2}[\s-]{0,1}\d{4}(\W|$) |
Notes |
|