Gunnar Hjalmarsson schreef:
> danlamb:
>> I need a regex to remove zeros after the . in a file name if they are
>> followed by another digit.
>>
>> Example: XXXXXX.001 becomes XXXXXX.1
>
> s/\.0+(?=[1-9])/./;
That rewrites the dot, and won't handle ".000".
I would write it like
s/(?<=\.)0+(?=[0-9])//;
A more precise answer is:
s/(?<=\.)0+(?=\d)//;
(because she said "digits" :)
I often see code that unnecessarily replaces something by itself,
like these:
s/\.0+(?=\d)/./;
s/(\.)0+(?=\d)/$1/;
s/(\.)0+(\d)/$1$2/;
s/\.0+(\d)/.$1/;
Maybe the Perl 5.10.x regex optimiser could be further optimised to
optimise those away. It looks easy to recognize that the substitution
part includes a start and/or an end section of the original.
--
Affijn, Ruud
"Gewoon is een tijger."
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/