08-12-2012 01:38 AM - edited 03-07-2019 08:17 AM
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
08-12-2012 03:10 AM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide