in reply to Partial Searches Against Multiple Wildcards
G'day p_jacobson,
Welcome to the Monastery.
The following code meets all of your expectations. It requires Perl v5.14 for the non-destructive transliteration and substitutions.
#!/usr/bin/env perl use v5.14; use warnings; use constant OLD => 1; my @data = ( [qw{1 ABFD-1234 AAA}], [qw{2 ABFD-178G BBB}], [qw{3 F2HB-9401 AAA}], [qw{4 ZDDR-00W5 DDD}], [qw{5 D7*D-48*6 EEE}], ); my @wild_cards = qw{940 ABFD-1 ABFD1 D7RD DD482}; for my $search (@wild_cards) { say $search; my $re = qr{@{[$search =~ y/-//dr =~ s//-?/gr =~ s/([A-Z0-9])/(?:$1|\\*)/gr ]}}; for my $datum (@data) { say "@$datum" if $datum->[OLD] =~ $re; } }
Output:
940 3 F2HB-9401 AAA ABFD-1 1 ABFD-1234 AAA 2 ABFD-178G BBB ABFD1 1 ABFD-1234 AAA 2 ABFD-178G BBB D7RD 5 D7*D-48*6 EEE DD482 5 D7*D-48*6 EEE
— Ken
|
|---|