Re: a regex question ..



Elvis Cehajic wrote:
Fabian Pilkowski wrote:

my $name = 'aaa2bbb3'; ( my $newname = $name ) =~ s/(\d)/0$1/g; # results in: $newname = 'aaa02bbb03'

Just keep in mind that this will change 'aaa11bbb12' to 'aaa0101bbb0102' which is probably not what the OP wants.

That's my interpretation as well. How about:

    (my $newname = $name) =~ s/(^|\D)(\d)(?=\D|$)/${1}0$2/g;
    rename $name, "new-$newname";

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.