Community discussions

MikroTik App
 
Azma
newbie
Topic Author
Posts: 44
Joined: Sat Sep 27, 2014 8:10 am

command "print where" not case insensitive

Wed Dec 07, 2022 5:42 pm

Hi,
print function seems to be case sensitive, does anybody know how to print a capitalized comment with case insensitive?
for example a rule with comment "ABCD", then print where comment "abc"?

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

Re: command "print where" not case insensitive

Wed Dec 07, 2022 6:21 pm

Make yourself a rule and follow it, so there's no need to screw things up.
print where comment~"(a|A)(b|B)(c|C)"
This cover all 8 cases: abc abC aBc aBC Abc AbC ABc ABC
 
Azma
newbie
Topic Author
Posts: 44
Joined: Sat Sep 27, 2014 8:10 am

Re: command "print where" not case insensitive

Thu Dec 08, 2022 4:45 am

Thanks, i was thingking regexp but just to confirm if i did it wrong.
I am sure that nobody want to use regexp to filter something.
Rules better to be implemented into software, human will never do it perfectly, But there must be a reason why they made it case sensitive.
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11439
Joined: Thu Mar 03, 2016 10:23 pm

Re: command "print where" not case insensitive

Thu Dec 08, 2022 9:26 am

Well, to me it's only natural to have things case-sensitive. Do 'a' and 'A' look the same? No, they don't, so why should they mean the same thing? Even in linguistic typing something in upper-case means (slightly) different than typing same in lower-case (the former is generally understood as shouting). In natural sciences and technical sciences upper-case letters and lower-case letters are very distinct. E.g. mJ stands for mili Joule while MJ stands for Mega Joule (Joule being unit of energy).

BTW, linux had always been case-sensitive, as were all the different Unix dialects preceeding it. Only MS f**ed up making things case-insensitive (another of their f**k-ups is reliance on file name extensions to identify file type).

From my point of view you should stop messing with different cases according to your daily inspiration and start using them in some coherent way ... and you won't need any regular expression or any other magic to filter output.
 
Azma
newbie
Topic Author
Posts: 44
Joined: Sat Sep 27, 2014 8:10 am

Re: command "print where" not case insensitive

Fri Dec 09, 2022 2:54 pm

thanks for your input guys, i got your point.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: command "print where" not case insensitive

Fri Dec 09, 2022 5:36 pm

for example a rule with comment "ABCD", then print where comment "abc"?

use this:
:global strfind do={
    :local chrfind do={
        :local chr $1
        :if (([:typeof $chr] != "str") or ($chr = "")) do={ :return "" }
        :local ascii " !\"#\$%&'()*+,-./0123456789:;<=>\?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
        :local conv  "====E===EEEE==E================E=UUUUUUUUUUUUUUUUUUUUUUUUUUEEEE==LLLLLLLLLLLLLLLLLLLLLLLLLLEEE="
        :local chrValue [:find $ascii [:pick $chr 0 1] -1]
        :if ([:typeof $chrValue] = "num") do={
            :local nv [:pick $conv $chrValue ($chrValue + 1)]
            :if ($nv = "=") do={:return $chr}
            :if ($nv = "E") do={:return ("\\$chr")}
            :if ($nv = "U") do={:return ("($chr|$[:pick $ascii ($chrValue+32) ($chrValue+33)])")}
            :if ($nv = "L") do={:return ("($[:pick $ascii ($chrValue-32) ($chrValue-31)]|$chr)")}
            :return "."
        } else={
            :return "."
        }
    }
    :local string $1
    :if (([:typeof $string] != "str") or ($string = "")) do={ :return "" }
    :local lenstr [:len $string]
    :local constr ""
    :for pos from=0 to=($lenstr - 1) do={
        :set constr "$constr$[$chrfind [:pick $string $pos ($pos + 1)]]"
    }
    :return $constr
}


print where comment~[$strfind ("abc")]

Who is online

Users browsing this forum: Bing [Bot], dioeyandika, GoogleOther [Bot], menyarito and 90 guests