beautypg.com

Google Message Security for Google Apps Administration Guide User Manual

Page 232

background image

232

Message Security for Google Apps Administration Guide

Match an Alphanumeric Format

Notes

The

\

before each period “escapes” the period—that is,

it indicates that the period is not a regex special
character itself.

In the example 1, no characters follow the last period, so
the regex matches any IP address beginning with
192.168.1., regardless of the number that follows.

In example 2,

\d

matches any digit from 0 to 9 after the

last period, and

{1,3}

indicates that the from 1 to 3

digits can appear after that last period. In this case, the
regex matches any complete IP address beginning with
192.168.1.. Note that this regex also matches invalid IP
addresses, such as 192.168.1.999.

Usage example

Match the purchase order numbers for your company. This
number has various possible formats, such as:

PO nn-nnnnn

PO-nn-nnnn

PO# nn nnnn

PO#nn-nnnn

PO nnnnnn

Regex example

(\W|^)po[#\-]{0,1}\s{0,1}\d{2}[\s-]{0,1}\d{4}(\W|$)

Notes

\W

matches any character that’s not a letter, digit, or

underscore. It prevents the regex from matching
characters before or after the number.

^

matches the start of a new line. Allows the regex to

match the number if it appears at the beginning of a line,
with no characters before it.

$

matches the end of a line. Allows the regex to match

the number if it appears at the the end of a line, with no
characters after it.

[#\-]

matches a pound sign or a hyphen after the

letters po, and

{0,1}

indicates that one of those

characters can occur zero or one times. Note that the

\-

(which indicates a hyphen) must occur last in the list of
characters within the square brackets.

\s

matches a space, and

{0,1}

indicates that a space

can occur zero or one times.

\d

matches any digit from 0 to 9, and

{2}

indicates that

exactly 2 digits must appear in this position in the
number.