Topic: Extract between parentheses and pad different length numbers
FROM:
img_20080423095549.jpg
img_20080423095549(1).jpg
img_20080423095549(10).jpg
img_20080423095549(2).jpg
TO:
000.jpg
001.jpg
010.jpg
002.jpg
USE:
0000%b(s/.+\((\d+).+/\1/);%b(s/img_.+/0/)(-3)
EXPLANATION:
0000 -----------------------> Add a few padding zeros, no matter how much but as many as the shortest string needs.
%b(s/.+\((\d+).+/\1/)--> extract digits between (...)
; ---------------------------> separate different actions
%b(s/img_.+/0/) --------> rename file without (...) to 0
(-3) ------------------------> keep the last three signs from string only.
0000(-3) is used to pad numbers with different length (1 or 10 or 100) to the same end length (001 and 010 and 100)
First i add a many 0's so all strings have at least the length they should have, then i take the amount of signs i really want from the right.
.