rohan_532 has asked for the wisdom of the Perl Monks concerning the following question:
i need to find a match from array which contains a word to be matched in another array below is the code i have done so far
my @needles = ("1-2 Steps", "5-7 Steps", "8-10 Steps", "catch"); my @haystacks = ("move 1-2 steps", "move 8-10 steps to hoist", "catch +the ball"); for my $needle (@needles) { my $found; for my $haystack (@haystacks) { if ($haystack =~ /\i\Q$needle\E\i/) { print "<br>"; print "Found [$needle] in [$haystack]\n"; print "</br>"; $found++; } } if (!$found) { print "<br>"; print "Couldn't find [$needle] anywhere!\n"; print "<br>"; } }
this code only matches the exact string
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex for case insensitive
by marinersk (Priest) on May 31, 2017 at 06:50 UTC | |
|
Re: regex for case insensitive
by AnomalousMonk (Archbishop) on May 31, 2017 at 07:51 UTC |