wildmat to perl regex

Marco d'Itri md at Linux.IT
Thu Feb 1 01:36:46 UTC 2001


Which conversion code should I use in the new controlchan?

Fluffy's controlchan:

        s/\$\|/\|/g;
        s/[^\\]\.[^*]/\?/g;
        s/^(.*)\$/$1/g;
        s/\.\*/*/g;
        s/\\([\@\$\+\.])/$1/g;


docheckgroups from ftp.tin.org:

        s:([.+^\${}|()\@\\]):\\$1:g;
        s/\*/.*/g;
        s/\?/.?/g;
#       s/^/^/;
        s/$/\$/;


Andrew Gierth in news.software.nntp:

sub wildmat_to_regex
{
    my $w = quotemeta shift;
    $w =~ s{\\([*?]|\\(\\?.)|\[(?:\\\^)?(?:\\\])?[^]]*\\\])}
           {($1 eq '*' ? '.*' :
             $1 eq '?' ? '.'  :
             defined($2) ? $2 :
             do { my $p = $1; $p =~ s/\\([][^-])/$1/g; $p; })}eg;
    return $w;
}


(Some day I'm going to wrap a decent perl API over Fluffy's module to
access the INN C API...)

-- 
ciao,
Marco



More information about the inn-workers mailing list