I am not sure Mikrotik support this basic function.
The need is to parse a string and extract some content based on regex.
I think mikrotik can only return true/false if the regex is matched, but can’t return $1, $2 … based on the matches (like any other coding language would be capable of doing).
For example the script below, where I would like the script to return the regex match between parenthesis.
$1 returns nothing
:local regexTestString "my test string bla bla"
:if ( $regexTestString ~".*(test.*)" ) do={
:put "regex match: $1"
}
I guess each language can have its own naming next to this feature, “capturing group” being one of them.
Perl calls it “extracting matches”, boen_robot in his post referenced earlier called it “regexmatch”
If it gets returned as $1 $2 would already be good (ie: without the capacity to tag each return with a distinctive name)
Not great to have this as unsupported considering that Mikrotik OS initially offsprings from a Linux distribution
Thanks for your update on the script.
I don’t get anything returned when running it, which is I guess expected as you called out this feature as being “unsupported”
I obviously went to the regex page of mikrotik, but it’s really short of ~20 lines.
It only states it follows POSIX (with 5 listed exceptions in bullet points), and list 8 areas where the Mikrotik device could use regex.
That’s it. There are no screenshot, implementation examples, scripts templates.
Eventually my workaround was partial, suboptimal, and involved nested string split/pick