12-27-2012 07:16 AM - edited 03-04-2019 06:30 PM
Folks,
I am looking to combine more than one regex into a single expression:
I have regex number 65001, 65002, 65003, 65004 upto 65030 into a single regex.
ip as-path access-list 10 permit _65001$
ip as-path access-list 20 permit _65002$
ip as-path access-list 30 permit _65003$
.
.
.
ip as-path access-list 300 permit _65030$
Is this below regex correct?
ip as-path access-list 10 permit _650[01-30]$
Thanks,
Nik
12-27-2012 07:32 AM
Hi,
I don't think this is possible with one line but i'm not a regexp expert though.
Anyway I think it can be done in 2 lines with:
ip as-path access-list 10 permit _650[0-2][0-9]$
ip as-path access-list 20 permit _65030$
Regards.
Alain
Don't forget to rate helpful posts.
12-27-2012 08:25 AM
Hi Nik and Alain,
Nik, the abbreviated as-path ACL you have suggested is not correct. The expression in brackets is always evaluated as a single character from a defined set. Your expression [01-30] defines a set that contains digits '0' (defined twice), '1', '2', and '3'. It is only a single digit, though. Your abbreviated as-path ACL therefore results into just four AS numbers: 6500, 6501, 6502, and 6503.
Alain, I believe it is possible to create a single-line as-path ACL that will do what Nik requires, however, the resulting regexp will require using the alternation operator. I believe you are correct in your assumption that you cannot write a single regular expression without this operator that will correctly match the range 65000 - 65030. The regexp can be, e.g.:
_650([0-2][0-9]|30)^
It has to be noted, though, that this form strongly reduces the readability and clarity of this expression, and therefore, I would not recommend using it. Over-optimizing things actually degrades them.
Best regards,
Peter
12-27-2012 10:13 AM
Hi Peter,
I'll try it on GNS3 , thanks for the info.
Regards.
Alain
Don't forget to rate helpful posts.
12-27-2012 10:14 AM
Disclaimer
The Author of this posting offers the information contained within this posting without consideration and with the reader's understanding that there's no implied or expressed suitability or fitness for any purpose. Information provided is for informational purposes only and should not be construed as rendering professional advice of any kind. Usage of this posting's information is solely at reader's own risk.
Liability Disclaimer
In no event shall Author be liable for any damages whatsoever (including, without limitation, damages for loss of use, data or profit) arising out of the use or inability to use the posting's information even if Author has been advised of the possibility of such damage.
Posting
_650([0-2][1-9]|10|20|30)_
Above is a variation of what Peter suggests, excluding 65000.
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