BGP Regular Expressions Examples

This topic is to discuss the following lesson:

Hey Rene,

I have found one of Swisscom BGP router from that expressions:

AS path access list 1
    permit ^$
    permit 650[0-9][0-9][)]$

permit ^$ : I think this one is written for locally originating routes

I can’t get a meaning the last one’s " [)] "section ? You have an idea?
By the way ; these ip as-path access lists , bgp filtering commands just filtering the AS’s that advertising from another BGP routers right?


Hi Deniz,

The first entry will match on prefixes that originated in this AS. The second one will match on everything that ends with 650XX). Anything in the 64512 – 65535 range are private AS numbers. The [)] is a bit strange, normally you use the [] for a range (like 0-9). I’m guessing that they use it to match on sub-AS numbers in a confederation? That’s the only time you will see a ) in the AS path:


Hi Rene,
Just looked at BGP looking glass server. How can one practice regular expression on this site? Thanks!

Hi A,

Most of the looking glass servers support regular expressions so that would be the best option to get some practice. If you want to practice this “locally” then I would configure some BGP routers and use route-maps for things like AS path prepending, this can be used as a nice simulation of the Internet.


Is it abnormal not really to be real fluent with these?

Don’t get me wrong I see the examples and as I went through lessons later on I see some of the examples come up that can be useful.

I am good with ones like:

^$ which can be useful for applying to everything (you use this one when dealing with Transit issues when multi-homing and need to filter) or ^63100$ apply to an AS specifically.

I also get and like the ones like Capture which would give every AS that goes through AS 51 those are cool. (I had to take a picture and upload because could not figure out how to use the underscores in posting on the forums is there a trick to that?)

Even the more complex examples I could use but I am not getting this like I can start coding with it or something I am understanding it on the level that I can login to this site to get something I need or perhaps google it and search for something I need (minus the simple ones that I used at beginning those stuck) is that ok? or do I really need to drill on these or just understand what they are used for in searches and filters and know that I can look these up when I need?

Also do these Regular Expressions just deal with BGP AS?

I have touched upon these in Microsoft PowerShell as well though they applied to everything but was used for similar purpose of searches or filters and such.

Hi Brian,

It’s normal I think…as network engineers, we don’t use regular expressions much. If you are into programming, you’ll use them quite a lot to match strings/numbers/etc… If you want to practice these, try a site like:

Paste in the output of a BGP table there and test it…it’s easier and quicker than testing regex on your router.

I wouldn’t worry about this too much though…when you need to use them for BGP, you can always look them up…test it, then apply it to your router. No need to memorize all the different options. When you need it, it’s probably a simple regex, nothing more.

The underscore works fine here btw? SHIFT + - (dash) does the job.


1 Like