This article outlines the interpretation of the as-path regex ".*64512*" and shares a method to filter routes that precede and end with AS64512
Topology:
router ------EBGP------ Internet node
Configuration policy that should accept the routes based on as-path regex ".*64512*" and reject other routes for reference:
root@router-re0# show | display set | match ACCEPT
set policy-options policy-statement ACCEPT term 10 from as-path TEST_ACCEPT
set policy-options policy-statement ACCEPT term 10 then accept
set policy-options policy-statement ACCEPT term 20 then reject
set policy-options as-path TEST_ACCEPT ".*64512*"
The "*" behind 64512 is interpreted as 0 or more repetitions of "64512", and "64512" precedes with ".*", which matches ANYTHING.
So, ".*64512*" is interpreted as: any AS path having anything, ending with 64512 or without it. Therefore, the aspath regex ".*64512*" matches all routes and doesn't serve any purpose.
Reference outputs from a lab node, where as-path regex ".*64512*" filters routes that do not have the 64512 sequence in them:
root@router-re0> show route receive-protocol bgp 10.219.48.254 aspath-regex ".*64512*"
inet.0: 997671 destinations, 997672 routes (997671 active, 0 holddown, 0 hidden)
Prefix Nexthop MED Lclpref AS path
* 1.0.0.0/24 10.219.48.254 65297 65110 24023 9498 13335 I
* 1.0.4.0/24 10.219.48.254 65297 65110 24023 55410 1299 7545 7545 38803 I
* 1.0.5.0/24 10.219.48.254 65297 65110 24023 55410 1299 7545 7545 38803 I
* 1.0.6.0/24 10.219.48.254 65297 65110 24023 55410 1299
7545 7545 38803 I
To match routes with as-path where any AS numbers precede and end with AS64512 use aspath regex ".* 64512$"
root@router-re0> show route receive-protocol bgp 10.219.48.254 aspath-regex ".* 64512$"
inet.0: 997658 destinations, 997659 routes (997658 active, 0 holddown, 0 hidden)
* 36.128.0.0/10 10.219.48.254 65297 65110 24023 9498 58453 64512 I
* 36.131.3.0/24 10.219.48.254 65297 65110 24023 9498 58453 64512 I
* 36.131.4.0/24 10.219.48.254 65297 65110 24023 9498 58453 64512 I
Check out the document below for more details on regex interpretation:
https://www.juniper.net/documentation/us/en/software/junos/routing-policy/topics/concept/policy-configuring-as-path-regular-expressions-to-use-as-routing-policy-match-conditions.html