Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Re: regex problem
- Ben Morrow
June 12, 2009, 8:16 pm
rate this thread
You could have reduced your example to just the code above (plus an
initialization of $line).
$prev contains regex metacharacters, in this case the parens, which
don't match literally. As on any occasion when you want to match a
string literally, you need \Q:
$line =~ s/^\Q$prev//;
Re: regex problem
Meh. I don't like substr (or index). Accessing strings by character
index just feels a bit crude for a high-level language like Perl.
Besides, I wouldn't have written the original program like that in the
first place. For a start, I would have incorporated the original match
and capture into the s/// up-front.
Still, substr is arguably cleaner than a pattern match you know will