Regex: How to get matched content?

Hi,

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"
}

returns:

regex match:

I have searched through the forum and google.
Very few results. The closest I was able to find was a response to an open discussion on feature requests, but no conclusion or follow-up:
http://forum.mikrotik.com/t/built-in-function-library/117288/2

Is there something obvious I’m missing, or is the feature simply absent?

Thanks

What you is looking for is called capturing group.
It des not look like RouterOS support capturing group or named capturing group.

{
:local regexTestString "my test string bla bla"

:if ( $regexTestString ~".*(?<tt>test.*)" ) do={
	:put "regex match: $tt"
}
}

RouterOS regex info:
https://wiki.mikrotik.com/wiki/Manual:Regular_Expressions

Thanks for your response,

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

Cheers