Regex to NOT find something...

Hi all,

I’m writing some scripts, and I would like to use regex’s to identify / not identify some of my rules / sets / whatever. Using a set like this (happens to be netwatch, but could be anything really):-

[admin@RTR] /tool netwatch> print
Flags: X - disabled
 #   HOST                 TIMEOUT              INTERVAL             STATUS
 0   203.255.255.110        1s                   10s                  up
 1   ;;; Monitor through to fw.i3
     116.255.255.2         1s                   1m                   up
 2   ;;; Monitor to BR AP.BR status
     203.255.255.66         1s                   5s                   down
 3   ;;; Something random
     203.255.255.115        1s                   10s                  up

I can do things like:-

[admin@RTR] /tool netwatch> print where comment~"Monitor"
Flags: X - disabled
 #   HOST                 TIMEOUT              INTERVAL             STATUS
 1   ;;; Monitor through to fw.i3
     116.255.255.2         1s                   1m                   up
 2   ;;; Monitor to BR AP.BR status
     203.255.255.66         1s                   5s                   down

But I’d also like to find the opposite. Things that DON’T have “Monitor” in the comment:-

print where comment!~"Monitor"
print where !comment~"Monitor"

Either of which seem to be valid syntax, but neither of which return any values.

Getting it to work on the CLI is the first step, then I can put it into my script.

Any help, greatly appreciated!

Thanks,

Wazza

did you figure it out? got the same problem right now :confused:
this is fine

/ip address print where address~"192.168.1."

but how do the opposite?

[admin@MikroTik] /interface wireless> /ip ad print where (address~"1" = false)
Flags: X - disabled, I - invalid, D - dynamic 
 #   ADDRESS            NETWORK         INTERFACE                                                                                
 2   4.4.4.4/32         5.5.5.5         wlan1                                                                                    
 4 I 7.7.7.7/32         6.6.6.6         wlan2



for these 2 output is the same:

/interface wireless> /ip ad print where address~"1"



[admin@MikroTik] /interface wireless> /ip ad print where (address~"1" = true)     
Flags: X - disabled, I - invalid, D - dynamic 
 #   ADDRESS            NETWORK         INTERFACE                                                                                
 0   ;;; default configuration
     192.168.88.33/24   192.168.88.0    ether1                                                                                   
 1   192.168.113.2/24      10.5.113.0      ether1                                                                                   
 3 D 192.168.113.246/24    10.5.113.0      ether1

thx for very fast reply.
it works as it should! thx again!

can i do in with if condition?
because this code just doesn’t seems to be right :slight_smile:

:if ($lastip ~"168."=true) do={
		:log error "test test"
		}

It works for me, tested in 5.26 and 6.4.

How are you testing this? I enclose the whole script in curly braces and run in the terminal (so that local variables will be accessible):
{
:local lastip “123.168.123.123”
:if ($lastip~“168.” = true) do={
:put “YES”
} else={
:put “NO”
}
}Then, when I’m done, I remove them from the final script, which won’t work in the terminal but works fine in System > Script or System > Scheduler:
:local lastip “123.168.123.123”
:if ($lastip~“168.” = true) do={
:put “YES”
} else={
:put “NO”
}