G
George Mpouras
I want to convert a OS filemask with possible wildcards to regex
What to you think of the following approach
$mask = "??-media*.wm?";
$mask=~s|\*\.\*|\*|g; # *.* -> *
$mask=~s|\.|\\.|g; # . -> \.
$mask=~s|\?|.|g; # ? -> .
$mask=~s|\*|.*?|g; # * -> .*?
$mask=~s/(\(|\)|\+|\^|\[|\]|\{|\}|\$|\@|\%)/\\$1/g; #escape ()+^[]{}$@%
$mask = qr/^$mask$/i;
What to you think of the following approach
$mask = "??-media*.wm?";
$mask=~s|\*\.\*|\*|g; # *.* -> *
$mask=~s|\.|\\.|g; # . -> \.
$mask=~s|\?|.|g; # ? -> .
$mask=~s|\*|.*?|g; # * -> .*?
$mask=~s/(\(|\)|\+|\^|\[|\]|\{|\}|\$|\@|\%)/\\$1/g; #escape ()+^[]{}$@%
$mask = qr/^$mask$/i;