Community discussions

MikroTik App
 
cwsupport
just joined
Topic Author
Posts: 11
Joined: Mon Apr 08, 2019 5:30 pm

Capture portion of identity into a variable

Fri May 06, 2022 8:26 pm

We have identities in this format AAA-BBB-CC-xxxxxx
We would like to capture the first three portions (AAA-BBB-CC) into a variable

Is there a way to pull via regex? I think ".*-" should return what we need. But I can't find out how to set it to a variable

I've gotten this far:
:local ident [/system identity get name];
Which returns the full identity

And this will then return AAA:
:local loc [:pick $ident 0 [:find $ident -]];
but that doesn't seem to work like cut so using 1 doesn't choose the next field

Any help would be appreciated.

Thanks
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Capture portion of identity into a variable  [SOLVED]

Fri May 06, 2022 9:18 pm

If the format is always the same then you can pick it with fixed numbers.

The first is 0 9
The second 11 17

You emulate cut but then you have loop through the string and cut away the first part (3 times -) and then start after the - and :len of string.

Who is online

Users browsing this forum: donkeyKong, UkRainUa and 22 guests