in reply to substitute characters in the RHS of a search & replace
Here's a solution that does what you're after. The substitution is:
s{\[\[(.*?)\]\]}{$1 =~ s/ /_/gr}e
I've added an additional test to check that various embedded brackets do not cause issues.
$ perl -Mstrict -Mwarnings -E ' my $x = q{Here are [[a variable number of words]] in brackets}; say $x; $x =~ s{\[\[(.*?)\]\]}{$1 =~ s/ /_/gr}e; say $x; my $y = q{Here are [[a variab]le number [ of ] wo[rds]] in brackets}; say $y; $y =~ s{\[\[(.*?)\]\]}{$1 =~ s/ /_/gr}e; say $y; ' Here are [[a variable number of words]] in brackets Here are a_variable_number_of_words in brackets Here are [[a variab]le number [ of ] wo[rds]] in brackets Here are a_variab]le_number_[_of_]_wo[rds in brackets
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: substitute characters in the RHS of a search & replace
by Anonymous Monk on Mar 08, 2013 at 23:10 UTC | |
by LanX (Saint) on Mar 08, 2013 at 23:57 UTC | |
by AnomalousMonk (Archbishop) on Mar 09, 2013 at 19:35 UTC | |
by LanX (Saint) on Mar 09, 2013 at 20:07 UTC | |
by AnomalousMonk (Archbishop) on Mar 09, 2013 at 21:04 UTC |