If not try this instead:
my $x = q{Here are [[a variable]] number [[of words]] in brackets}; say $x; $x =~ s{\[\[(.*?)\]\]}{ (my $x=$1) =~ s/ /_/g; $x }ge; say $x;
added a /g to allow multiple chunks to be processed.
Here are [[a variable]] number [[of words]] in brackets Here are a_variable number of_words in brackets
But to improve readability I would rather opt against one-liner and call a function in the replacement part
sub blank2under { my $x=shift; $x =~ s/ /_/g; return $x; }
Cheers Rolf
and here a generic function to simulate /r
sub rx (&$) { my $c_regex=shift; local $_=shift; $c_regex->(); return $_ } my $x = q{Here are [[a variable]] number [[of words]] in brackets}; print "$x\n"; $x =~ s(\[\[(.*?)\]\])( rx {s/ /_/g} $1 )ge; print "$x\n";
In reply to Re^3: substitute characters in the RHS of a search & replace
by LanX
in thread substitute characters in the RHS of a search & replace
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |