below is my script that scans each line of the input file against list of annotations. for every occurance
I tag the term from the line with the annotation tag. The regex works perfectly without \Q..\E operator, but if I don’t include \Q..\E I get a range error. So In the situation below I have to keep substitution valid and at the same time take care of the range. Hope the question is clear.
while (<FILE>) {
chomp $_;
foreach $word (@array) {
@cells = split /\t/, $word;
$value = $cells[0];
$replace = $cells[1];
chomp $value;
chomp $replace;
$_=~s/\Q\b[\w\-]*$value[\w\-]*\b\E)/<$replace>$&<\\$replace>/ig;
}
print $_,"\n";
}
My guess is that your
$valuecontains regex meta characters. This is easy enough to solve; either use$value = quotemeta $value;before matching and leave out\Q...\Ecompletely, or put the\Q...\Earound$valueonly:$_ =~ s/\b[\w\-]*\Q$value\E[\w\-]*\b/.../ig;