in reply to global string replace

perl -e' $string = "X*X*X*X"; $NEW = 20; $string =~ s/ (?: ^ | \* ) \K X (?= \* | $ ) /$NEW/xg; print "$string\n"; ' 20*20*20*20

Replies are listed 'Best First'.
Re^2: global string replace
by AnomalousMonk (Archbishop) on Jun 07, 2019 at 19:11 UTC

    NB: The regex  \K operator (effectively, variable-width positive look-behind) is only available with Perl versions 5.10+.


    Give a man a fish:  <%-{-{-{-<