Thread Maske Regex
(14 answers)
Opened by hobbyperler at 2009-09-12 09:47
Vielleicht hilft dir folgendes Schnipsel weiter:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 { my %special = ( 'id' => "\\d+", '' => "\\*", ); sub mask2regex { my( $mask ) = @_; my @rx = split /\*(\w*)\*/, $mask; # edit: negative look behind entfernt my $rx; $rx .= $_ % 2 == 0 ? "\Q$rx[$_]\E" : $special{$rx[$_]} for 0 .. $#rx; return qr/$rx/; } # mask2regex } my $mask = '*id*-**sp.dat'; my $regex = mask2regex($mask); # qr/(?-xism:\d+\-\*sp\.dat)/ MfG Last edited: 2009-09-12 14:54:55 +0200 (CEST) perl -E'*==*",s;;%ENV=~m,..$,,$&+42;e,$==f;$"++for+ab..an;@"=qw,u t,,print+chr;sub f{split}say"@{=} me"'
|