Not sure you need the /i, as your example uses numbers.my $pattern = '...'; $temp =~ s/${pattern}.{6}//s || $temp =~ s/.{6}${pattern}//s;
Instead of creating a whole new variable to match the 321, is there a simpler way to reverse the $pattern variable explicitly in a regex?But what if the pattern is more complicated? And why do you consider creating a "whole new variable" such a big deal? I guess if your pattern is just a simple string without characters special to the regexp engine, you could write
but I wouldn't. The following is, IMO, much simpler:$temp =~ s/${\scalar reverse $pattern}.{6}//s || $temp =~ s/.{6}${\scalar reverse $pattern}//s;
my $rpattern = reverse $pattern; $temp =~ s/$rpattern.{6}//s || $temp =~ s/.{6}$rpattern//s;
In reply to Re^3: Regex - remove characters (pattern not terminated)
by JavaFan
in thread Regex - remove characters (pattern not terminated)
by twaddlac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |