Given the variables:
my $var1 = "fish";
my $var2 = "ocean";
My input strings can be either fishin_ocean or fishout_ocean.
How do I write a Perl regex to match both the input strings, where parts of the regex are in $var1 and $var2? This one (where the string is in $var3) doesn't return either of the above strings:
$var3 =~ /$var1.+?$var2/;
Edit from OP's answer:
I think it is the special square braket at the end that is causing the problem
my $a = "slash_wideiscan"; my $b = "_mnn3h_reg[0]";
my @array1 = qw (slash_wideiscanps_mnn3h_reg[0]
slash_wideiscanptlr_mnn3h_reg[0]
slash_wideiscanps_mnn0h_reg);
for my $element (@array1) {
if ($element =~ /($a.+?$b)/) {
print "YES : $element\n";
} else {
print "NO : $element\n";
}
}
Answer that came back was
NO : slash_wideiscanps_mnn3h_reg[0]
NO : slash_wideiscanptlr_mnn3h_reg[0]
NO : slash_wideiscanps_mnn0h_reg
I actually want
YES : slash_wideiscanps_mnn3h_reg[0]
YES : slash_wideiscanptlr_mnn3h_reg[0]
NO : slash_wideiscanps_mnn0h_reg