Hi everyone,
I’m working on a MikroTik script and could use some help. My goal is to check if a command contains any of several patterns like “add name=”, “edit name=”, or “delete name=”. If a match is found, I want to store the matched pattern in a variable called matchedPattern and then log this variable.
Here’s the script I have so far:
:local command "just test"
:local patterns {"add name="; "edit name="; "delete name="; "disable name="; "enable name="}
:local matchedPattern ""
# Determine which pattern the command matches
:foreach pattern in=$patterns do={
:if ([:find $command $pattern] != "") do={
:set matchedPattern $pattern
}
}
:log info $matchedPattern
However, when I test it, the log shows all the patterns (“add name=”, “edit name=”, “delete name=”, “disable name=”, and “enable name=”) even if the $command doesn’t match any of them.
I think I might be doing something wrong, but I’m not sure what. Could anyone help me correct this script or guide me on how to achieve the desired functionality?
Thanks in advance for your assistance!