Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

New Member

Regular Expression Question

Hi,

Could someone please explain to me how the following regular expressions work?

^123_.*_45$ = This looks to me as though it would match an AS starting with 123 and ending in 45 with only 1 AS in between them.

^123_.*45 = What does this match? the book I'm reading says it matches an AS path beginning with 123, with zero or more intermediate AS's and delimiters and ending with an AS whote last two digits are 45.

The second of these examples confuses me more. I understand it starts with 123 then a delimiter and then the . means any character. So for me reading this all I can see is that it starts with 123_ and then has any character immediatly followed by 45. So if, as the example states, this actually means it can have zero or more intermediate AS numbers in between the 123 and 45, how does this work?

Thanks,

Adam

Everyone's tags (3)
1 REPLY
Cisco Employee

Regular Expression Question

Hello Adam,

^123_.*_45$ = This looks to me as though it would match an AS starting with 123 and ending in 45 with

only 1 AS in between them.

Not entirely. The following regexp means: The AS_PATH must start with AS number 123, then it may contain an arbitrary count of arbitrary AS numbers, and must end with AS number 45. The ".*" expression stands for "any character arbitrarily many times, including a delimiter between AS numbers".

If you wanted to have an regexp that starts with AS 123, ends with AS 45 and allows for only a single AS inbetween, the regexp would be sligthly more complicated:

^123_[0-9]+_45$

^123_.*45 = What does this match? the book I'm reading says it matches  an AS path beginning with 123, with zero or more intermediate AS's and  delimiters and ending with an AS whote last two digits are 45. 

This is correct.

So for me reading this all I can see is that it starts with 123_ and then has any character immediatly followed by 45.

Do not forget the role of the * quantifier here. What you described here would be true for the regexp ^123_.45$ without the asterisk. However, the regexp ^123_.*45$ allows the any character including delimiter to repeat arbitrarily many times (0 or more).

Does this make sense? Please feel welcome to ask further!

Best regards,

Peter

244
Views
0
Helpful
1
Replies