Community discussions

MikroTik App
 
Dani1250
just joined
Topic Author
Posts: 13
Joined: Wed Apr 14, 2021 6:21 pm
Location: Lisbon, Portugal

Regex for Numeric Range

Wed Sep 29, 2021 6:09 pm

Good afternoon,

I want to get the addresses between 192.168.0.0 and 192.168.63.0 through the regex. My regex expression is: "192\\.168\\.\b([0-9]|[1-5][0-9]|6[0-3])\b"
From what I researched the mikrotik does not support "\b". So how can I apply the regex?


Any help, I appreciate it.

Compliments,
Daniel Rodrigues
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Regex for Numeric Range

Wed Sep 29, 2021 7:23 pm

 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Regex for Numeric Range

Wed Sep 29, 2021 7:30 pm

I want to get the addresses between 192.168.0.0 and 192.168.63.0 through the regex. My regex expression is: "192\\.168\\.\b([0-9]|[1-5][0-9]|6[0-3])\b"
From what I researched the mikrotik does not support "\b". So how can I apply the regex?

MikroTik support POSIX syntax without class (:digit: etc.), do not support other languages syntax
\b is for? word boundaries?

As @msatter wrote, can be used "in" but you do not explain what you needs.
# work because can be specified a group of IPs
:put (192.168.12.54 in 192.168.0.0/18)
:put (192.168.12.54/32 in 192.168.0.0/18)

# do not work because "in" do not accept intervals
:put (192.168.12.54 in 192.168.0.0-192.168.63.0)
:put (192.168.12.54 in 192.168.0.0-192.168.63.255)

This identify an IP
((25[0-5]|(2[0-4]|[01]?[0-9]?)[0-9])\\.){3}(25[0-5]|(2[0-4]|[01]?[0-9]?)[0-9])

But must match only from 192.168.0.0 to 192.168.63.0 keeping the 0 at the end or what is probably wanted, from 192.168.0.0 to 192.168.63.255???
# from 192.168.0.0 to 192.168.63.0 keeping the 0 at the end
(192\\.168\\.(6[0-3]|[1-5]?[0-9])\\.0)

# from 192.168.0.0 to 192.168.63.255
(192\\.168\\.(6[0-3]|[1-5]?[0-9])\\.(25[0-5]|(2[0-4]|[01]?[0-9]?)[0-9]))
 
Dani1250
just joined
Topic Author
Posts: 13
Joined: Wed Apr 14, 2021 6:21 pm
Location: Lisbon, Portugal

Re: Regex for Numeric Range  [SOLVED]

Wed Oct 06, 2021 11:28 pm

Good night,

Thanks for the help @msatter and @rextended.
What I want to do is check if an IP address is present in an LSA Type 1 and if it belongs to that range I mentioned earlier, so I'm using a regular expression.

I solved the problem by putting a dot at the end. My regex expression now is: "192\\.168\\.([0-9]|[1-5][0-9]|6[0-3])\\."
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Regex for Numeric Range

Wed Oct 06, 2021 11:43 pm

Thanks for coming back on this and it is a nice solution you got.
 
Dani1250
just joined
Topic Author
Posts: 13
Joined: Wed Apr 14, 2021 6:21 pm
Location: Lisbon, Portugal

Re: Regex for Numeric Range

Thu Oct 07, 2021 1:10 am

I have to say thanks again for the help.

Who is online

Users browsing this forum: baragoon and 23 guests