in reply to Escaping quotemeta() in regex
to handle embedded \E and \Q as needed. It removes any backslash by itself, and one backslash from every pair of backslashes; that should effectively undo a layer of quotemeta, if I'm thinking straight. I found that \E, when part of an interpolated string variable, is not recognized as a legitimate escape, so its use here is just as a flag for your post-processing.my $expr = quotemeta 'foo.\E{2}\Qbar'; $expr =~ s{\\\\E(.*?)(?:\\\\Q|$)}{ (my $unprotect = $1) =~ s/\\(\\?)/$1/g; $unprotect; }ge;
|
|---|