cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1502
Views
5
Helpful
5
Replies

Need help in creating a Regex in ACS 5.8

Hello Members,

 

I need some help in creating a regex in ACS 5.8 to permit all ip address in the command set.

 

The commands I want to use in the command set are :

ip address <x.x.x.x> 255.255.255.252

ip mroute vrf mssbdata <x.x.x.x> 255.255.255.255 <x.x.x.x>

neighbor <x.x.x.x> activate

X.X.X.X can be any ip address.

 

Please suggest !

 

1 Accepted Solution

Accepted Solutions

How about this one?  It does some moderate checking to ensure that some 1-3 digit dotted decimal is entered, but no range checking is done in each decimal.

^([0-9]{1,3}\.){3}[0-9]{1,3}$

 

View solution in original post

5 Replies 5

Arne Bier
VIP
VIP

Regular expression syntax doesn't provide a numerical range checking operator, so we have to build it ourselves.  My suggestion below is tailored towards valid IPv4 address ranges as much as possible.

 

([1-9]|[1-9][0-9]|[12][0-9][0-9])\.([0-9]|[1-9][0-9]|[12][0-9][0-9])\.([0-9]|[1-9][0-9]|[12][0-9][0-9])\.([0-9]|[1-9][0-9]|[12][0-9][0-9])$

 

Without complicating the regex any more, it will allow examples such as

1.0.0.0 - 299.299.299.299 (but the IOS would flag an error if you entered an illegal IP address - the question is whether you want your regex to guard you from that too?  Yes, maybe.  Would be nice.  But would possibly make the regex look even uglier.

 

I am open to other suggestions

 

Test your regex here https://regex101.com/

 

 

I have made v2.0 that now enforces the legal IPv4 syntax

 

^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$

 

I told you'd it's gonna get ugly :-)

Hello Arme,

Thanks for sharing the regex, I tried using the regex below:
"^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$"

unfortunaty it's too long be added in the command set.
We don't want to restrict the user to enter any ip address till the time they are using the authorized commands in the command set.
Example below:
ip address 255.255.255.252

x.x.x.x can be any Ip address.

Please suggest.

Regards

Singh

How about this one?  It does some moderate checking to ensure that some 1-3 digit dotted decimal is entered, but no range checking is done in each decimal.

^([0-9]{1,3}\.){3}[0-9]{1,3}$

 

Hello Arne,

 

Thanks for the regex, It worked like a charm.. Thanks Again...

 

Regards

 

Harshdeep Singh