regular expressions

Answered Question
Jul 17th, 2008

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])+$

I have this problem too.
0 votes
Correct Answer by Marwan ALshawi about 5 years 9 months ago

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

Correct Answer by mohammedmahmoud about 5 years 9 months ago

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.

  • 1
  • 2
  • 3
  • 4
  • 5
Average Rating: 4.4 (5 ratings)
Marwan ALshawi Thu, 07/17/2008 - 02:45

^ 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

chilihead74 Thu, 07/17/2008 - 03:54

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])+$

mohammedmahmoud Thu, 07/17/2008 - 04:05

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.

Marwan ALshawi Thu, 07/17/2008 - 04:09

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

Correct Answer
mohammedmahmoud Thu, 07/17/2008 - 04:18

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.

Correct Answer
Marwan ALshawi Thu, 07/17/2008 - 04:29

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

mohammedmahmoud Thu, 07/17/2008 - 04:37

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.

Actions

Login or Register to take actions

This Discussion

Posted July 17, 2008 at 2:39 AM
Stats:
Replies:7 Avg. Rating:4.4
Views:394 Votes:0
Shares:0
Tags: No tags.

Discussions Leaderboard

Rank Username Points
1 15,007
2 8,150
3 7,730
4 7,083
5 6,742
Rank Username Points
160
82
70
69
55