in reply to Re^4: Matching Many Strings against a Large List of Hash Keys (case insensitively, longest key first)
in thread Matching Many Strings against a Large List of Hash Keys (case insensitively, longest key first)

Yes, that assumption comes from using an assembled regex match. Node has been updated again to make the assumption explicit.

For kicks, let's try to handle overlapping keys using the assembled regex approach:
use Regexp::Assemble; use Regexp::Exhaustive qw(exhaustive); use List::Util qw(reduce); my @keys = map { quotemeta } keys %hash; my $key_re = Regexp::Assemble->new->add(@keys)->re; for my $string (@strings) { my $match = reduce { length($a) > length($b) ? $a : $b } exhaustive($string => qr/\b($key_re)\b/i); print "Found '$match' in '$string'\n" if defined $match; }

But then, the performance hit of using Regexp::Exhaustive removes any justification to use the assembled regex in the first place. Ho hum.
  • Comment on Re^5: Matching Many Strings against a Large List of Hash Keys (case insensitively, longest key first)
  • Download Code