REN implied .*


Scott Mintz
May 20, 2008
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.
$ >SmithAdj20180530.txt

$ >SmithRcpt20180530.txt

$ 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?
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).

ren /n "::(Smith)(Adj|Rcpt)(\d\d\d\d)(\d\d)(\d\d)\Z" ::\1_\2-\3-\4-\5
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