REN implied .*

samintz

Scott Mintz
May 20, 2008
1,557
26
Solon, OH, USA
In the following code I did not specify an extension in the REN command, but it still did the rename as if there was an implied ".*" added to end.
Code:
[C:\TC22]
$ >SmithAdj20180530.txt

[C:\TC22]
$ >SmithRcpt20180530.txt

[C:\TC22]
$ ren "::(Smith)(Adj|Rcpt)(\d\d\d\d)(\d\d)(\d\d)" ::\1_\2-\3-\4-\5
C:\TC22\SmithAdj20180530.txt -> C:\TC22\Smith_Adj-2018-05-30.txt
C:\TC22\SmithRcpt20180530.txt -> C:\TC22\Smith_Rcpt-2018-05-30.txt
     2 files renamed

Is this WAD?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,689
106
Albuquerque, NM
prospero.unm.edu
As I understand it, your regex means that the filename must contain the stuff you specify. To limit it only filenames containing only the stuff you specify, you'd use /A (at the start) or /Z or /z (at the end).

Code:
ren /n "::(Smith)(Adj|Rcpt)(\d\d\d\d)(\d\d)(\d\d)\Z" ::\1_\2-\3-\4-\5
 
May 20, 2008
12,178
133
Syracuse, NY, USA
Yeah, but in the case of REN someone is going out of their way to preserve text before and after the regex (as if REN is using @REGEX to find the file and @REREPLACE to rename it) ... all of which is OK with me. But there's a point of view from which the behavior is surprising.
 

Similar threads