Regex renaming

Jan 19, 2011
596
14
Norman, OK
I have 20 files, 1.txt, 2.txt, ... 19.txt, 20.txt.
I want to rename 1-9 as 01-09.

Why does this regex rename change not only the single digit text files, but the double digits also?

The rename command is shown and defined as follows...
Code:
*ren /n ::^(\d)\.txt$ ::0\1.txt
-------------------------------
*ren - rename command overriding aliases

/n   - just show me what would happen

::   - it's the source filename regex
^    - beginning of line
(    - start capture group
\d   - a single digit
)    - end capture group
\.   - escaped period overriding the wildcard any character effect
txt  - the text string "txt"
$    - end of line

::   - it's the target file regex
0    - the text string "0"
\1   - use the first matching group from the source filename regex
.txt - the text string ".txt"
And the result is...
Code:
[C:\temp]
12:20:45 $ *ren /n ::^(\d)\.txt$ ::0\1.txt
C:\temp\1.txt -> C:\temp\01.txt
C:\temp\10.txt -> C:\temp\100.txt
C:\temp\11.txt -> C:\temp\101.txt
C:\temp\12.txt -> C:\temp\102.txt
C:\temp\13.txt -> C:\temp\103.txt
C:\temp\14.txt -> C:\temp\104.txt
C:\temp\15.txt -> C:\temp\105.txt
C:\temp\16.txt -> C:\temp\106.txt
C:\temp\17.txt -> C:\temp\107.txt
C:\temp\18.txt -> C:\temp\108.txt
C:\temp\19.txt -> C:\temp\109.txt
C:\temp\2.txt -> C:\temp\02.txt
C:\temp\20.txt -> C:\temp\200.txt
C:\temp\3.txt -> C:\temp\03.txt
C:\temp\4.txt -> C:\temp\04.txt
C:\temp\5.txt -> C:\temp\05.txt
C:\temp\6.txt -> C:\temp\06.txt
C:\temp\7.txt -> C:\temp\07.txt
C:\temp\8.txt -> C:\temp\08.txt
C:\temp\9.txt -> C:\temp\09.txt
    20 files would be renamed
 
May 20, 2008
10,634
82
Syracuse, NY, USA
The '^' is getting lost. Either use '^^' or "quote" the regex.

Code:
t:\> *ren /n ::^(\d)\.txt$ ::0\1.txt
T:\1.txt -> T:\01.txt
T:\10.txt -> T:\100.txt
     2 files would be renamed

t:\> *ren /n ::^^(\d)\.txt$ ::0\1.txt
T:\1.txt -> T:\01.txt
     1 file would be renamed

t:\> *ren /n ::"^(\d)\.txt$" ::0\1.txt
T:\1.txt -> T:\01.txt
     1 file would be renamed