So, for space between ASNs, you don't need to use "_", just space is sufficient.
Original Message:
Sent: 02-25-2024 18:03
From: LEEBAHI
Subject: BGP AS REGX practice
I think I got it.
it will be .*13*.
Much appreciated!!
------------------------------
Be kind!!
Original Message:
Sent: 02-25-2024 16:05
From: LEEBAHI
Subject: BGP AS REGX practice
Thanks Farid.
it works. But I have been following juniper documentation that shows we can use underscore to represent white space in AS path.
For example:
AS 11 12 13 14 15 155 2
How do we define AS path regex to filter AS path based on transit AS say AS 13 in my example. I tried _13_ but it did not work.
Much appreciated!!
------------------------------
Be kind!!
Original Message:
Sent: 02-25-2024 01:39
From: FARID AKHUNDOV
Subject: BGP AS REGX practice
Hi,
Technically, your regex "2$" should match every route, which is originated from AS 2. However, because there is no "space" in front of 2, Junos interprets it as literally AS path of 2 only, without anything in front of it. So, if the AS path contained ONLY ASN 2, it would match.
Therefore, try using following regex instead of currently used - ".* 2$". In this case, it will match any AS path which contains ASN 2 at the end.
Also, I would advise to test regex, which you are intending to use, on the routing table before you use it in policy. In your case, if you check the routing table with the command like show route as-path-regex "2$", it will not produce output, while running show route as-path-regex ".* 2$", you will see needed route.
------------------------------
FARID AKHUNDOV
Original Message:
Sent: 02-24-2024 21:26
From: LEEBAHI
Subject: BGP AS REGX practice
Hi everyone,
I am trying to learn how BGP AS path REGX can be used to manipulate BGP attributes. I have set up my mock set up as show below:

Above we have:
ISP AS 2 sending 8.8.8.8 with AS path 11 12 13 14 155 2 towards AS1. On MX1 we receive this route . We then apply BGP REGX to search AS path with certain criteria and set local-pref 200 . We then apply this policy as export towards IBGP peer MX2 . MX1 has been configured to set next hop to its peering IP ( 12.12.12.1) so MX2 will accept the route.
My REGX command does not take effect:
MX1:

MX1 does receive BGP route 8.8.8.8/32 with AS 11 12 13 14 15 155 2 as shown above.
We then apply the following policy as export to IBGP group (MX2)
set policy-options policy-statement TEST from as-path BGP-REGX
set policy-options policy-statement TEST then local-preference 200
set policy-options policy-statement TEST then next-hop self
set policy-options policy-statement TEST then accept
set policy-options as-path BGP-REGX 2$
The policy say if there is numeral 2 at the very end of AS path, the local pref should be set to 200, so 8.8.8.8/32 should have local pref set to 200 before it is announced to MX2.
I verified BGP REGX syntax is correct:

I then applied the policy as export to iBGP group ( MX2) and clear the BGP session :
MX1:
set protocols bgp group INT export TEST
set protocols bgp group INT neighbor 12.12.12.2

Nothing advertised!
If I removed:
delete policy-options policy-statement TEST from as-path BGP-REGX
8.8.8.8 is advertised with local pref 200.

So clearly BGP REGX statement is a issue
Syntax " $2 " bgp regex is correct as verified on "regex101.com" link shown above.
What am i missing?
Thanks !!
------------------------------
Be kind!!
------------------------------