in reply to Re: Comparing multiple strings
in thread Comparing multiple strings
... a ... regex solution for this problem?
Since the application seems to call for exact string matching, I would prefer a hash lookup or any-based solution as discussed already in this thread.
But a regex solution might look like this:
Since the regex is \A \z anchored for an exact match, thec:\@Work\Perl\monks>perl -wMstrict -le "my $t1 = 'EV-1891'; my $t2 = 'EV-DKL1'; ;; my ($rx_name_set) = map qr{ \A (?: $_) \z }xms, join '|', map quotemeta, reverse sort $t1, $t2 ; print $rx_name_set; ;; for my $name (@ARGV) { if ($name =~ $rx_name_set) { print qq{name '$name' in set}; } if ($name !~ $rx_name_set) { print qq{name '$name' NOT in set}; } } " EV-1891 FOO (?msx-i: \A (?: EV\-DKL1|EV\-1891) \z ) name 'EV-1891' in set name 'FOO' NOT in set
Give a man a fish: <%-{-{-{-<
|
|---|