Community discussions

MikroTik App
just joined
Topic Author
Posts: 1
Joined: Sat Jun 13, 2015 8:31 pm

Regex outside of the find function?

Sat Jun 13, 2015 8:54 pm

I want to run some regular expression searches on a list of comments for a script I'm working on but as far as I can tell you can only use them in the instance of:
find <expression>
Example: /ip hotspot hosts find comment~"(regex)"
The other find command only works on strings
:find <arg> <arg> <start>
Example: :find "abc" "a" -1
Is there a reason we can't use regular expressions for the second argument? Is there a similar function that can be used to do this? As far as I can tell the only time that it is possible to do them in the current version is to search a whole list, one particular field, and the return is a list of IDs that meet that criteria.

Example of what I'm asking
:local CheckingOut [/ip hotspot ip-binding find comment~"COD"];
:foreach entry in=$CheckingOut do={
#There would be a few of these for different date formats
:local start  [:find $entry "(Regex for different date formats)"];  #THIS DOESN'T WORK#
:local end ($start+#length of date format#);
:local date [:pick [/ip hotspot ip-binding get $entry comment] $start $end];
The alternative solution that I'm using for now is making multiple arrays of entries with different COD and running code on each of those separately. What I could do in <100 lines of code is going to take over 300 lines of code due to multiple instances of the same thing being run on different smaller arrays instead of an all-encompassing method on one larger array.

Is there a solution to this I'm missing? Are there plans to make regular expressions more widely usable in future versions? Thanks for any input!
Member Candidate
Member Candidate
Posts: 159
Joined: Mon Mar 17, 2014 11:30 am
Location: Amsterdam

Re: Regex outside of the find function?

Thu May 05, 2016 12:26 pm

+1; bump.

Who is online

Users browsing this forum: No registered users and 17 guests