Community discussions

MikroTik App
 
User avatar
CZFan
Forum Guru
Forum Guru
Topic Author
Posts: 2098
Joined: Sun Oct 09, 2016 8:25 pm
Location: South Africa, Krugersdorp (Home town of Brad Binder)
Contact:

Regex search - Finding exact match

Sun Sep 25, 2022 12:59 pm

Hi,

Hope someone can help me here, I am trying to do a print in firewall connection for a specific port number, but not getting results I expected.

I tried all the below commands, the first one returns all with 500 in it, i.e. 500, 50018, etc, the last 2 seems to be not "supported" by Mikrotik as the coloring on the characters indicate a problem, and then it returns "ALL" connections
/ip firewall connection print where src-address~":500"
/ip firewall connection print where src-address~":500$"
/ip firewall connection print where src-address~"^:500$"
 
sindy
Forum Guru
Forum Guru
Posts: 10205
Joined: Mon Dec 04, 2017 9:19 pm

Re: Regex search - Finding exact match  [SOLVED]

Mon Sep 26, 2022 10:12 am

In Mikrotik scripting, the $ symbol is used to expand a variable, as in
:local srcport 500 ; /ip firewall connection print where src-address~":$srcport"
To use it as the "end of string" symbol in a regexp, you have to escape it, as in
/ip firewall connection print where src-address~":500\$"

Who is online

Users browsing this forum: hasan2221, normis and 94 guests