in reply to Re: regex in REPLACEMENT in s///
in thread regex in REPLACEMENT in s///

Aye, /r (introduced in 5.14) is key here.

You can use /r on the s/// too.

my $res = $str =~ s{ (\d+) }{ $1 =~ s/(\d)/3/gr }xer;
And we don't need those captures.
my $res = $str =~ s{ \d+ }{ $& =~ s/\d/3/gr }xer;

Replies are listed 'Best First'.
Re^3: regex in REPLACEMENT in s///
by tybalt89 (Monsignor) on Sep 12, 2023 at 23:21 UTC

    I probably would have gone for

    $res = $str =~ s{ \d+ }{ $& =~ tr//3/cr }xer;

    or

    $res = $str =~ s{ \d+ }{ 3 x length $& }xer;

    TMTOWTDI gone wild :)

      Well, I saw it as an exercise in using a nested s///. If you don't, then you might as well use:

      my $res = $str =~ s/\d/3/gr;

        He actually says he wanted 333333.56 and not 333333.33, so nope...