Regular expressions

The ability to perform a filter match on confederations in the AS path and/or communities is supported. This filter allows customers to configure match criteria for specific confederation sets and sequences within the AS path so that they can be filtered out before cluttering the service provider’s routing information base (RIB). When matching communities, the filter allows customers to configure match criteria within the community value.

SR OS uses regular expression strings to specify match criteria for:

A regular expression is expressed in the form of terms and operators.

A term for an AS path regular expression must meet the following criteria.

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

A raw hex format can be keyed to represent all extended communities. For example, "ext:0102:dc0000020032" is the same as ‟target:65530:20”. Hex values ‟ext:” and ‟&” can also be used to filter extended communities. The first expression is applied to the type/subtype of the extended community and the second expression to the value. In this case, hex values can also be used in the operands; for example, the value {3,f} matches a minimum 3 and a maximum 15 repetitions of the term.

The regular expression OPERATORS are listed in Table: Regular expression operators .

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.

<>

Matches any AS path numbers containing a confederation SET or SEQ.

&

Matches ‟:” between terms of a community string (applicable to extended communities origin, target, bandwidth, ext only).

Examples of ‟target:”, ‟origin:” and ‟ext:” community strings are listed in Table: Community strings examples .

Table: Community strings examples
Example expression Example matches

"ext:..&f(.*)[af]$"

Matches the community "ext:0002:fffa0000001a".

'target:1&22

Matches community target:100:221.

target:^1&^22

Matches community target:100:221.

target:(.*)0$&(.*)1$

Matches community target:100:221.

origin:^1&(.*)1$

Matches community origin:100:221.

Examples of AS path and community string regular expressions are listed in Table: AS path and community regular expression examples .

Table: AS path and community regular expression examples
AS path to match criteria Regular expression Example matches

Null AS path

null1

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 AS number 11

11*

Null AS path

11

11 11

11 11 11

11 … 11

Path of any length that begins with AS numbers 11, 22, 33

11 22 33 .*

11 22 33

11 22 33 400 500 600

Path of any length that ends with AS numbers 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 AS numbers 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 AS number 11, followed by one or more occurrences of AS number 22, followed by one or more occurrences of AS number 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 AS number must be 11 or 22

(. 11) | (. 22) .*

or . (11 | 22) .*

100 11

200 22 300 400

Path of length one or two whose second AS number may be 11 or 22

. (11 | 22)?

100

200 11

300 22

Path whose first AS number is 100 and second AS number 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 AS numbers to match a single AS number

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 AS number 11

11? or 11{0,1}

Null AS path

11

One through four occurrences of AS number 11

11{1,4}

11

11 11

11 11 11

11 11 11 11

One through four occurrences of AS number 11 followed by one occurrence of AS number 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 AS number can be anything, including nonexistent

. .* or . .{0,}

100

100 200

11 22 33 44 55

AS number is 100. Community value is 200.

^100:200$

100:200

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

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

11:100

22:100

11:200

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

^11:(1.*)$

11:1

11:100

11:1100

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

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

11:1

100:2002

333:55553

AS number 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

AS number is 11 or 22. Community value ends in 33 or 44.

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

11:33

22:99944

22:555533

Range of Community values

100&^([1-9][0-9]|[1-9][0-9][0-9]|1[0-9][0-9][0-9]|2000)$"

100:10

100:11

100: …

100:2000

1 The null keyword matches an empty AS path.