in reply to Re: Reg exp questions
in thread Reg exp questions

How to combine the expressions? for ex, if I want to replace ()[] by the same char, how to can i combine it?

$str =~ s/()[]/"/g;

Replies are listed 'Best First'.
Re^3: Reg exp questions
by ww (Archbishop) on Nov 08, 2014 at 19:48 UTC

    Quoting is in M$Win style:

    C:\>perl -E "my $str='abc()[]xyz'; $str =~ s/[()\[\]]{1}/\"/g; say $st +r; abc""""xyz

    IOW, use a character class and escaping; both of which can be found in perldoc's perlre* pages. Note that the quantifier is redundant here, but could be useful were you trying to substitute two-at-a-time. OTOH, the /g modifier is NOT optional for this use case.

    C:\>perl -E "my $str='a)bc([]xyz'; $str =~ s/[()\[\]]{2}/\"/g; say $st +r; a)bc"]xyz

    ++$anecdote ne $data