3

I saw this explanation in the JNCIS study guide book ch1 (community regex examples) and i'm a bit confused:

^65000:.{2,3}$ - AS number is 65000, community value is any 2 or 3 digit number ex. 65000:123, 65000:16, and 65000:999

^65010:45.{2}9$ - AS number is 65010. The community value is a five-digit number that begins with 45 and ends with 9. The third and fourth digits are any single number repeated twice ex. 65010:45119, 65010:45999, and 65010:45339.

If .{2} means any single number repeated twice, then i'd have argued .{2,3} if any single number repeated at least twice and at most thrice and not any 2 or 3 digit number as explained in the book.

What is the right interpretation of these 2 regex ?

Thanks,

2 Answers 2

2

I set up a quick'n'dirty lab and it would appear that the first example is actually correct, rather than the second.

The first example, I've got three routes being received, each tagged with a community of 65000:123, 65000:999 or 65000:16:

{primary:node0}
root@lab-srx240h> show route table CE3.inet.0 community ^65000:.{2,3}$ detail

CE3.inet.0: 7 destinations, 7 routes (7 active, 0 holddown, 0 hidden)
3.3.3.3/32 (1 entry, 1 announced)
        *BGP    Preference: 170/-101
                Next hop type: Router, Next hop index: 1383
                Address: 0x15d464c
                Next-hop reference count: 8
                Source: 192.168.88.3
                Next hop: 192.168.88.3 via reth4.100, selected
                State: <Active Ext>
                Peer AS: 65505
                Age: 7:34
                Task: BGP_65505.192.168.88.3+179
                Announcement bits (1): 0-KRT
                AS path: 65505 65505 I
                Communities: 65000:123 target:65505:1
                Accepted
                Localpref: 100
                Router ID: 192.168.6.1

192.168.5.0/24 (1 entry, 1 announced)
        *BGP    Preference: 170/-101
                Next hop type: Router, Next hop index: 1383
                Address: 0x15d464c
                Next-hop reference count: 8
                Source: 192.168.88.3
                Next hop: 192.168.88.3 via reth4.100, selected
                State: <Active Ext>
                Peer AS: 65505
                Age: 7:34
                Task: BGP_65505.192.168.88.3+179
                Announcement bits (1): 0-KRT
                AS path: 65505 I
                Communities: 65000:999 target:65505:1
                Accepted
                Localpref: 100
                Router ID: 192.168.6.1

192.168.88.0/31 (1 entry, 1 announced)
        *BGP    Preference: 170/-101
                Next hop type: Router, Next hop index: 1383
                Address: 0x15d464c
                Next-hop reference count: 8
                Source: 192.168.88.3
                Next hop: 192.168.88.3 via reth4.100, selected
                State: <Active Ext>
                Peer AS: 65505
                Age: 7:34
                Task: BGP_65505.192.168.88.3+179
                Announcement bits (1): 0-KRT
                AS path: 65505 I
                Communities: 65000:16 target:65505:1
                Accepted
                Localpref: 100
                Router ID: 192.168.6.1

The second example I've got a route tagged with 65010:45129 (not 65010:45119 as per the book) and I still get a match:

{primary:node0}
root@lab-srx240h> show route table CE3.inet.0 community ^65010:45.{2}9$ detail
CE3.inet.0: 7 destinations, 7 routes (7 active, 0 holddown, 0 hidden)
1.0.0.10/32 (1 entry, 1 announced)
        *BGP    Preference: 170/-101
                Next hop type: Router, Next hop index: 1383
                Address: 0x15d464c
                Next-hop reference count: 8
                Source: 192.168.88.3
                Next hop: 192.168.88.3 via reth4.100, selected
                State: <Active Ext>
                Peer AS: 65505
                Age: 2:23
                Task: BGP_65505.192.168.88.3+179
                Announcement bits (1): 0-KRT
                AS path: 65505 65505 I
                Communities: 65010:45129 target:65505:1 origin:65505:1
                Accepted
                Localpref: 100
                Router ID: 192.168.6.1

So yes, .{2} means any two characters and .{2,3} means any two-to-three characters.

2
  • Excellent - so the book is wrong or ambiguous and we're all sane.
    – Zac67
    Commented May 7, 2018 at 11:04
  • I had a look online for the errata mentioned in the book - corerouting.net, which is now dead (heck the book is 14 years old). Even back-tracked with the arhive.org wayback machine, but it shows no corrections. Commented May 7, 2018 at 21:43
4

Not exactly sure about any Junos specialties but with 'standard' regex, .{2} matches any two characters, repeating or not.

If you'd need two of the same character it should be looking something like (.)\1.

.{2,3} matches two or three of any character (same or different).

1
  • Correct for standard regex and it's what i though was right for junos too but the book's example somewhat contradicts, thus my question. Thanks
    – wax
    Commented May 5, 2018 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.