(Note that I used a '-' (dash) as the replacement character just to make the example more clear.) (Update: See discussion of \Q \E and friends in Quote and Quote-like Operators section of perlop. See also quotemeta.)c:\@Work\Perl\monks>perl -wMstrict -le "my $a = 'A_D1[1]'; ;; my $str = '123 A_D1 XYZ A_D1[1] BLAH A_D1[1] BLAH'; print qq{str = '$str'}; ;; $str =~ s{ \b \Q$a\E [ ] }{-}xmsg; print qq{str = '$str'}; " str = '123 A_D1 XYZ A_D1[1] BLAH A_D1[1] BLAH' str = '123 A_D1 XYZ -BLAH -BLAH'
Give a man a fish: <%-{-{-{-<
In reply to Re: Replacing string with []
by AnomalousMonk
in thread Replacing string with []
by doofus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |