0

I want to write a regex in Juniper MX960 router for BGP including 3 AS paths with first element is constant, second and third are wildcard. I found that we can put as numbers manually like this:

"9121+ (one|two|three|...) (one|two|three|...)". This doesn't work for me cause i don't know whole as numbers in second and third level. They can be anything. I want them to be "any".

"9121+ any+ any+" « I need this.

Thank you.

h0m3r
  • 25
  • 10
  • Need clarification. Must exactly two ASes follow 9121? Or do you want 9121 followed by zero or more ASes? Please be specific. – Jeff Loughridge May 23 '13 at 01:34
  • I need 3 ASes. First is 9121+ second and third can be anything. But the array must be consists of 3 ASes. – h0m3r May 23 '13 at 08:53

1 Answers1

1

Assuming you want to match on any AS path that consists of exactly 3 AS numbers, with the first being 9121, you would want this:

9121 .+ .+

Olipro
  • 2,967
  • 18
  • 18
  • For the OP's edification, I'll point out that JUNOS regexes differ from Unix regexes in signficant ways such as the basic unit of matching is an AS rather than a character. – Jeff Loughridge May 23 '13 at 14:37
  • Firstly, doesn't it need to be end with ".$"? I also need it to include bgp prepends. "+" is represent prepends in Juniper. I mean it can be multiple occurences of the same AS element such as: "9121+ 34927+ 8685+" can represent: "9121 34927 34927 8685" or "9121 9121 9121 34927 8685 8685". I need 3 unique ASes after all. First is 9121 with prepend. – h0m3r May 23 '13 at 17:25
  • .+ can only match a single AS and the regex does not qualify a partial match, it must cover the entire path. so no, $ should not be necessary (although equally, it won't do any harm) – Olipro May 23 '13 at 17:50
  • Ok then i will try "9121+ .+ .+" and will inform you. By the way how about this? "9121+ [0-65536]+ .$" – h0m3r May 23 '13 at 21:00
  • no, that's invalid, firstly, AS numbers nowadays are 32 bit, not 16 bit, and secondly, even if they were 16 bit, it'd only go to 65535 – Olipro May 23 '13 at 21:32