Regular expressions

7210 SAS uses regular expression strings to specify match criteria for:

A regular expression is expressed in terms of terms and operators. A term for an AS path regular expression is:

A term for a community string regular expression is a string that is evaluated character by character and is composed of:

The regular expression OPERATORS are listed in the following table.

Table: Regular expression operators

Operator

Description

|

Matches the term on alternate sides of the pipe.

*

Matches multiple occurrences of the term.

?

Matches 0 or 1 occurrence of the term.

+

Matches 1 or more occurrence of the term.

( )

Used to parenthesize so a regular expression is considered as one term.

[ ]

Used to demarcate a set of elementary or range terms.

-

Used between the start and end of a range.

{m,n}

Matches least m and at most n repetitions of the term.

{m}

Matches exactly m repetitions of the term.

{m,}

Matches m or more repetitions of the term.

^

Matches the beginning of the string - only allowed for communities.

$

Matches the end of the string - only allowed for communities.

\

An escape character to indicate that the following character is a match criteria and not a grouping delimiter.

Examples of AS path and community string regular expressions are listed in the following table.

Table: AS path and community regular expression examples

AS path to match criteria

Regular expression

Example matches

Null AS path

null 1

Null AS path

AS path is 11

11

11

AS path is 11 22 33

11 22 33

11 22 33

Zero or more occurrences of ASN 11

11*

Null AS path

11

11 11

11 11 11

11 … 11

Path of any length that begins with ASNs 11, 22, 33

11 22 33 .*

11 22 33

11 22 33 400 500 600

Path of any length that ends with ASNs 44, 55, 66

.* 44 55 66

44 55 66

100 44 55 66

100 200 44 55 66

100 200 300 44 55 66

100 200 300 … 44 55 66

One occurrence of the ASNs 100 and 200, followed by one or more occurrences of the number 33

100 200 33+

100 200 33

100 200 33 33

100 200 33 33 33

100 200 33 33 33 … 33

One or more occurrences of ASN 11, followed by one or more occurrences of ASN 22, followed by one or more occurrences of ASN 33

11+ 22+ 33+

11 22 33

11 11 22 33

11 11 22 22 33

11 11 22 22 33 33

11 … 11 22 … 22 33 …33

Path whose second ASN must be 11 or 22

(. 11) | (. 22) .*

or

. (11 | 22) .*

100 11

200 22 300 400

Path of length one or two whose second ASN might be 11 or 22

. (11 | 22)?

100

200 11

300 22

Path whose first ASN is 100 and second ASN is either 11 or 22

100 (11 | 22) .*

100 11

100 22 200 300

Either AS path 11, 22, or 33

[11 22 33]

11

22

33

Range of ASNs to match a single ASN

10-14

10 or 11 or 12 or 13 or 14

[10-12]*

Null AS path

10 or 11 or 12

10 10 or 10 11 or 10 12

11 10 or 11 11 or 11 12

12 10 or 12 11 or 12 12

Zero or one occurrence of ASN 11

11? or 11{0,1}

Null AS path

11

One through four occurrences of ASN 11

11{1,4}

11

11 11

11 11 11

11 11 11 11

One through four occurrences of ASN 11 followed by one occurrence of ASN 22

11{1,4} 22

11 22

11 11 22

11 11 11 22

11 11 11 11 22

Path of any length, except nonexistent, whose second ASN can be anything, including nonexistent

. .* or . .{0,}

100

100 200

11 22 33 44 55

ASN is 100. Community value is 200.

^100:200$

100:200

ASN is 11 or 22. Community value is any number.

^((11)|(22)):(.*)$

11:100

22:100

11:200

ASN is 11. Community value is any number that starts with 1.

^11:(1.*)$

11:1

11:100

11:1100

ASN is any number. Community value is any number that ends with 1, 2, or 3.

^(.*):(.*[1-3])$

11:1

100:2002

333:55553

ASN is 11 or 22. Community value is any number that starts with 3 and ends with 4, 5 or 9.

^((11)|(22)):(3.*[459])$

11:34

22:3335

11:3777779

ASN is 11 or 22. Community value ends in 33 or 44.

[^((11|22)):(.*((33)|(44)))$

11:33

22:99944

22:555533

1 The null keyword matches an empty AS path.