I need to process the string with regexp and change x->y if is number around.
String: 2x2x2 2x 2x2x 2x2x2x2x2
Regexp: s/([0-9])x([0-9])/$1y$2/g
my $string = "2x2x2 2x 2x2x 2x2x2x2x2";
$string =~ s/([0-9])x([0-9])/$1y$2/g;
print "$string\n";
I expect: 2y2y2 xx 2x 2y2x 2y2y2y2y2
But result: 2y2x2 2x 2y2x 2y2x2y2x2 (not all 2×2 changed)
What should I do?
Try the below regex: