Feature Request - Regex Capturing Groups

Looking for the ability to use capturing groups in regex, which doesn’t appear to be present in the OS.

Something like this would be ideal:


[admin@MikroTik] > :local testString "FQDN: host.documentation.net"; :if ( $testString ~"^FQDN: (.*)\$" ) do={ :put $1 }

Where $1 is the contents of the first capturing group, returning “host.documentation.net” at the end of the script.

If there’s already a means to accomplish this, please let me know. I haven’t been able to find much in my digging.

{
:local testString "FQDN: host.documentation.net"
:local removeThisAndAllBefore "FQDN: "
:put [:pick $testString ([:find $testString $removeThisAndAllBefore] + [:len $removeThisAndAllBefore]) [:len $testString]]
}

True, that works for the example.

But there can be multiple capture groups from a regex (and even named ones), so it could be used to extract multiple values from one string, and return the captured groups as an array. And that’s where this be useful.

Still think it’s a valid feature request, I even made one myself: http://forum.mikrotik.com/t/built-in-function-library/117288/1

But there has not been a lot of progress on adding much* functionality to scripting in many years…

* only: :timestamp, :rndnum, :rndstr

Possibly due to no recent graduates from computer software engineering in Latvia…OR
Cheap assed owners who dont want to hire the necessary staff to make MT really shine and sing!!

Exactly. Returning the capturing groups’ results as an array would be perfect.

That will cover the immediate requirement. Thanks!

(I would still like to see full capturing group support though. It's much easier than getting into string manipulation, especially if there are multiple matches to consider.)

My solution didn’t mean that such a function shouldn’t be implemented, like “:search” & “:replace”…

Fair enough. Regex group captures is pretty esoteric. Just string processing is annoying, they should do something. I'd take anything.

As you know, you can "string" together a solution to most things, it just time-consuming or a lot of code.