Community discussions

MikroTik App
 
mudasir
Member Candidate
Member Candidate
Topic Author
Posts: 278
Joined: Tue Apr 29, 2008 3:38 am
Location: Karachi, Pakistan
Contact:

Regular expression match

Fri Jan 28, 2011 5:09 am

Hi,

I would like to know how can i do regular expression matching.
I am trying to figure out all active users in "/ppp active print" which starts with "cn-", like
cn-mudasir
cn-abc
cn-xyz
So how can i only print information about the users having cn- at the begining of the user id.
 
changeip
Forum Guru
Forum Guru
Posts: 3830
Joined: Fri May 28, 2004 5:22 pm

Re: Regular expression match

Fri Jan 28, 2011 6:02 am

something like ...

/ppp active print where name~"$cn-"

i didnt even test it, but i think the trick is to use ~ instead of = ...
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Regular expression match

Fri Jan 28, 2011 6:38 am

Yup, exactly. Only thing to change is that $ means end of the string, so you want to use ^ instead to match at the beginning.
 
mudasir
Member Candidate
Member Candidate
Topic Author
Posts: 278
Joined: Tue Apr 29, 2008 3:38 am
Location: Karachi, Pakistan
Contact:

Re: Regular expression match

Fri Jan 28, 2011 8:18 am

Thanks allot.

I got that working in 4 of my v4.16 ROS, but is there any way to get this working in v3.23. Because I have 2 ROS v3.23 and 4 ROS v4.16.

Please let me know if there is any method in v3.23
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Regular expression match

Fri Jan 28, 2011 8:52 am

There is no regular expression matcher in v3.23. So if you really need it then upgrade or loop through all the users looking for 'cn' in users name.
 
mudasir
Member Candidate
Member Candidate
Topic Author
Posts: 278
Joined: Tue Apr 29, 2008 3:38 am
Location: Karachi, Pakistan
Contact:

Re: Regular expression match

Fri Jan 28, 2011 9:09 am

Ok.

I can loop through all users, but can you please guime me how can i check name for "cn".
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Regular expression match

Fri Jan 28, 2011 9:27 am

:foreach i in=[/ppp active find] do={
:local uname [/ppp active get $i name];
:if ( [:pick $uname 0 3] = "cn-") do={ :put $uname}
}
 
mudasir
Member Candidate
Member Candidate
Topic Author
Posts: 278
Joined: Tue Apr 29, 2008 3:38 am
Location: Karachi, Pakistan
Contact:

Re: Regular expression match

Fri Jan 28, 2011 9:32 am

Thanks allot.

Got it working..

Who is online

Users browsing this forum: No registered users and 29 guests