Get only integers from array of strings

Hello,
I need to get only numeric part from an array of strings so I tried global command tonum, as below but it did not work.

:local $numericpart [:tonum $output]

$output variable is the array of strings and it usually outputs something like this:

user admin logged in from 192.168.100.5



user admin logged in from 192.168.100.20

I need to take only the ip address from that array of strings, the result wanted is just
192.168.100.5
192.168.100.20

Thanks

:toip is a better try because you have IP addresses.

This might work to find the IP address and you have to adapt it yourself.

([:pick $data 0 [:find $data "\n"]]~"^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}")

Thank you but it returns a “false” value for variable $test
:local test ([:pick $output 0 [:find $output “\n”]]~“[1]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}”)

maybe I should try something like this?

#get numeric values from string
:local test [:pick "$output" 1 14]

#convert it to int
:local test2 [:tonum "$test"]

but it does not work the same


  1. 0-9 ↩︎

This is the script:

{   
   :while ([:len $output]!=0) do={
      :if ([:pick $output 0 [:find $output "\n"]]~"^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}") do={
      :do {:put ([:pick $output 0 [:find $output "\n"]].$cidr)} on-error={}
      }
   :set $output [:pick $output ([:find $output "\n"]+1) [:len $output]]
   }
   }

Your output contains new lines “\n” and those are the delimiters. This will go through the whole string (list) and display the IP addresses. I can’t test it and it and it is a bit to warm here to use the brain fully. :wink:

Source: this thread http://forum.mikrotik.com/t/address-lists-downloader-dshield-spamhaus-drop-edrop-etc/133640/24