in reply to Re^2: Regex - remove characters (pattern not terminated)
in thread Regex - remove characters (pattern not terminated)
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Regex - remove characters (pattern not terminated)
by twaddlac (Novice) on Jun 29, 2010 at 19:03 UTC |