To follow up on @tomaskir great suggestions…
One alternative to adding a bunch of new :str_X_ things, is full support regular expressions, specifically capture groups and replace. Thought is a “:regex” command might be able to encompose a lot of use cases. Idea being it would return an ROS array with the “matches” returned from the regex groups defined in the match= regular expression provided, based on data in from=
:global mystr "blah, blah, blah"
:global matches [:regex match=/blah/ from=$mystr multiline greedy global]
:put [:typeof $matches]
# array
:put $matches
# blah;blah;blah
:put [:len $matches]
# 3
For string substitution,
:global replacedstring [:regex find="blah" replace="hello" from=$mystr]
:put [:typeof $replacedstring]
# string
Basically have some light version of “sed” and “awk” be nice. Regex isn’t for the faint of heart, but neither is BGP which supports regex in V7. Thinking it at least be cleaner script code than “[:strright [:strleft $x] 3” .
Yup this comes up which then requires more complex conditional logic to avoid needing it…
Here perhaps another possible simplification is a wrapper around GNU date, so perhaps “:datestr” that wraps it? The “modern” date in Linux support some humanizing options that pretty handy in /bin/sh script, see this gdate cheatsheet for example.
The options just follow the man pages, except with the ROS “=” method, so follow Bash shell usage a Linux date:
# returns the "7th day of last month"
bash> gdate --date "-1 month" +"%Y-%m-07"
# 2021-12-07
be the following in ROS, with added format=
[user@ROS]> :datestr date="-1 month" format="+\"%Y-%m-07\""
# 2021-12-07
As more sophisticated version of “:datestr” also have an “as-value” that get the current Mikrotik “time” type (e.g. weeks ago from 1970-epoch time).
- Finally, I would really like to get access to why an error occurred in on-error blocks. Here is what I would love:
:do {
# things
} on-error e do={
:put “Failed, reason: $e”
};
>
That's a good one, and since "$e" likely be a string, a "_simple_ string find" operation from your 1 above is also needed with it :wink:.