Community discussions

MikroTik App
 
Tal
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 57
Joined: Wed Jun 17, 2015 2:17 am

Substring from Variable

Wed Jun 17, 2015 2:27 am

I have a variable that stores an IP with a subnet:
:local IPADDR "192.168.1.1/24"
If I want another variable set to just the first part of that (just the IP, without the "/24"), is there a way to do this?

Related, but sort of separate question:
I noticed that MikroTik supports regex - is there a way to maybe use regex to specify which part of the first variable I want to assign to the second variable? Kind of like "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" - that sort of thing? Or is regex only used on MikroTik to do layer 7 domain matching?
 
User avatar
PaulsMT
MikroTik Support
MikroTik Support
Posts: 282
Joined: Tue Feb 10, 2015 3:21 pm

Re: Substring from Variable

Wed Jun 17, 2015 9:56 am

{
:local IPADDR "192.168.1.1/24"
:local TEST [:pick $IPADDR 0 [:find $IPADDR "/"]];
:put $TEST
}
 
Tal
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 57
Joined: Wed Jun 17, 2015 2:17 am

Re: Substring from Variable

Wed Jun 17, 2015 1:22 pm

Awesome! Thanks!