in reply to Q regex escape within variable
\Q interpretation is not done by the regex engine, but by string interpolation. Except you add the \Q in a single quote string, so the interpolation does not happen, and the \Q and \E are still there for the regex engine to read, though they don't have meaning in a regex. If you want to pre-process a string so that its special chars are excaped, you can use quotemeta, which is what \Q does implicitly. my $pref = "^".quotemeta($1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Q regex escape within variable
by palkia (Monk) on Mar 28, 2017 at 09:37 UTC |