#!/usr/bin/perl
use strict;
use warnings;
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 "
";
print "Found [$needle] in [$haystack]\n";
print "";
$found++;
}
}
if (!$found) {
print "
";
print "Couldn't find [$needle] anywhere!\n";
print "
";
}
}
####
S:\Steve\Dev\PerlMonks\P-2017-05-31@0243-RegEx-Case-Insensitive>perl regex0a.pl
Unrecognized escape \i passed through in regex; marked by <-- HERE in m/\i <-- HERE 1\-2\ Steps\i/ at regex0a.pl line 12.
Unrecognized escape \i passed through in regex; marked by <-- HERE in m/\i1\-2\ Steps\i <-- HERE / at regex0a.pl line 12.
Couldn't find [1-2 Steps] anywhere!
Unrecognized escape \i passed through in regex; marked by <-- HERE in m/\i <-- HERE 5\-7\ Steps\i/ at regex0a.pl line 12.
Unrecognized escape \i passed through in regex; marked by <-- HERE in m/\i5\-7\ Steps\i <-- HERE / at regex0a.pl line 12.
Couldn't find [5-7 Steps] anywhere!
Unrecognized escape \i passed through in regex; marked by <-- HERE in m/\i <-- HERE 8\-10\ Steps\i/ at regex0a.pl line 12.
Unrecognized escape \i passed through in regex; marked by <-- HERE in m/\i8\-10\ Steps\i <-- HERE / at regex0a.pl line 12.
Couldn't find [8-10 Steps] anywhere!
Unrecognized escape \i passed through in regex; marked by <-- HERE in m/\i <-- HERE catch\i/ at regex0a.pl line 12.
Unrecognized escape \i passed through in regex; marked by <-- HERE in m/\icatch\i <-- HERE / at regex0a.pl line 12.
Couldn't find [catch] anywhere!
S:\Steve\Dev\PerlMonks\P-2017-05-31@0243-RegEx-Case-Insensitive>
##
##
my $needle_regex = quotemeta $needle;
if ($haystack =~ /$needle_regex/i) {
##
##
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;
my $needle_regex = quotemeta $needle;
for my $haystack (@haystacks) {
if ($haystack =~ /$needle_regex/i) {
print "
";
print "Found [$needle] in [$haystack]\n";
print "";
$found++;
}
}
if (!$found) {
print "
";
print "Couldn't find [$needle] anywhere!\n";
print "
";
}
}
##
##
if ($haystack =~ /\Q$needle\E/i) {
##
##
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 =~ /\Q$needle\E/i) {
print "
";
print "Found [$needle] in [$haystack]\n";
print "";
$found++;
}
}
if (!$found) {
print "
";
print "Couldn't find [$needle] anywhere!\n";
print "
";
}
}