in reply to Regexp and metacharacters
Don't know why a single statement is preferable, but this may do the trick:
>perl -wMstrict -le "my $s = q{' * + [] {} '}; print qq{[[$s]]}; ;; $s =~ s{ (?: \A ['\"])? (.*?) (?: [\"'] \z)? }{\Q$1}xmsg; print qq{[[$s]]}; " [[' * + [] {} ']] [[\ \*\ \+\ \[\]\ \{\}\ ]]
Update: Got rid of /e regex modifier and quotemeta call, used \Q string modifier instead; removed some runaway backslashes.
Update: s{ \A ['"]? (.*?) ["']? \z }{\Q$1}xms is simpler, makes use of /g modifier unnecessary (after jwkrahn).
|
|---|