BGP regular expressions - use of backslash for confederations

BGP can use regular expressions extensively for route manipulation or filtering. The backslash character "\" is used to negate the special usage of particular characters when using regular expressions. This is especially useful when dealing with BGP Confederations

BGP confederations use sub-ASes that are denoted using parentheses like this: (65200). For example, take a look at this detailed output of a BGP route:

R3#show ip bgp 11.11.11.11 BGP routing table entry for 11.11.11.11/32, version 6 Paths: (1 available, best #1, table Default-IP-Routing-Table) Advertised to update-groups: 1 (24) 1 192.168.12.1 (metric 2) from 2.2.2.2 (2.2.2.2) Origin IGP, metric 0, localpref 100, valid, confed-external, best

Note that the sub-AS 24 is denoted using parentheses.

However, regular expressions use parentheses as special characters. Specifically, the parentheses “(” and “)” are used to group specific portions of the regular expressions in much the same way as you would when using arithmetic. They are also used to OR expressions when using the “|” pipe character.

So in order to cancel out their special meaning and have them be used as simple text to be matched, you must use the “\” character. So “\(” is used to manipulate the open parenthesis as a simple text character. Similarly, “\)” is used to manipulate the close parenthesis as a simple text character.

Therefore, in order to match (65200) as text, we must use “\(” and “\)” in place of “(” and “)”. Thus, when referring to the sub-AS of 65200 using regular expressions, it must be denoted like so:

\(65200\)

Links:

https://forum.networklessons.com/t/bgp-regular-expressions-examples/1017/15?u=lagapides

https://networklessons.com/bgp/bgp-regular-expressions-examples

https://networklessons.com/bgp/bgp-confederation-explained