cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1975
Views
12
Helpful
7
Replies

regular expressions

chilihead74
Level 1
Level 1

can anyone pls explain the following regular expression examples, what the exact state? i don't check it...

ip as-path access-list 1 permit ^(8245_).*

ip as-path access-list 1 permit ^(13024_)*$

ip as-path access-list 1 permit ^(20605 *)+(28880 *|30820 *|29330 *)*$

ip as-path access-list 10 permit ^([0-9])+_([0-9])+$

2 Accepted Solutions

Accepted Solutions

Hi Marwan,

With regular expressions the Parentheses "( )" are used to nest characters for matching, it doesn't reflect confederation directly, to use it to match a confederation we must use "\" (escape character) which is used if an operator is inside the AS-Path (mainly used in the case of confederation) to remove its special meaning ex: AS-Path "(213 217) 765 312" to match on AS 213 we use the regular expression "^\(213_" in order not to be understood as an operator, or also "^\(213 217\)".

BR,

Mohammed Mahmoud.

View solution in original post

Common Regular Expressions for AS Path Filters Regular Expression Routes Targeted

^$ Routes originating from this AS.

^2_ All routes from a directly connected neighbor in AS 2.

^2$ Routes originated by a neighbor in AS 2.

_3_ Routes containing AS 3.

{1 2} Aggregate route using the as-set option. Routes from AS 1 and AS 2 form the aggregate.

(65530) Confederation peer. The peer is in AS 65530

dear mohamed thanks for the reply

this info from Cisco® BGP-4 Command and Configuration Handbook

i think what u have said right

about the \

if i want to match the $ itself i can use

\$

thanks

View solution in original post

7 Replies 7

Marwan ALshawi
VIP Alumni
VIP Alumni

^ mean strat with

$ mean end so that mean next hop last AS

. mean one match

* any matching

+ 0 or more occurance from the prevouse chrectors

_ mean space for example if u have ASs like

10 200 15 20

_15_ match the 15

_20$ match last AS 20

_20*

match 20 and 200

good luck

if helpful Rate

thx for explanation, but I'm still a little confused by the last one because of the brackets, may you can explain this one?

ip as-path access-list 10 permit ^([0-9])+_([0-9])+$

Hi,

"^" means the beginning of a line and "$" means the end of a line.

"[ ]" means any character listed between the brackets - can be written in 2 formats; [1234] or [1-4] -> means 1 or 2 or 3 or 4 - if contiguous like this example use the "-"

"+" means one or more instances of the character or pattern (at least once) - written after the required character(s).

Grabbing all these together, thus "^([0-9])+_([0-9])+$" means, an AS-Path list consisting of any 2 ASN, each has at least one digit from 0 to 9.

Please check this out "Cisco Regular Expression Pattern Matching Characters":

http://www.cisco.com/en/US/docs/ios/12_2/termserv/configuration/guide/tcfaapre_ps1835_TSD_Products_Configuration_Guide_Chapter.html#wp1022889

BR,

Mohammed Mahmoud.

the brackets relate to what is called confideration bgp peer

which is ASs within an AS it is used with big bgp domains

so

it match two peers within the confideration

first AS first one begin with anumber between 0-to-9 and the + Matches one or more sequences of the pattern

the next AS the same between 0-9 and the + Matches one or more sequences of the pattern

if helpful rate

Hi Marwan,

With regular expressions the Parentheses "( )" are used to nest characters for matching, it doesn't reflect confederation directly, to use it to match a confederation we must use "\" (escape character) which is used if an operator is inside the AS-Path (mainly used in the case of confederation) to remove its special meaning ex: AS-Path "(213 217) 765 312" to match on AS 213 we use the regular expression "^\(213_" in order not to be understood as an operator, or also "^\(213 217\)".

BR,

Mohammed Mahmoud.

Common Regular Expressions for AS Path Filters Regular Expression Routes Targeted

^$ Routes originating from this AS.

^2_ All routes from a directly connected neighbor in AS 2.

^2$ Routes originated by a neighbor in AS 2.

_3_ Routes containing AS 3.

{1 2} Aggregate route using the as-set option. Routes from AS 1 and AS 2 form the aggregate.

(65530) Confederation peer. The peer is in AS 65530

dear mohamed thanks for the reply

this info from Cisco® BGP-4 Command and Configuration Handbook

i think what u have said right

about the \

if i want to match the $ itself i can use

\$

thanks

Hi Marwan,

You are very welcomed, yes we use the "/" as an escape character in order to be able to match one of the operator characters, like you said for example the "$".

BR,

Mohammed Mahmoud.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Innovations in Cisco Full Stack Observability - A new webinar from Cisco