Regex problem: \xnn not recognized as a hex character

May 23, 2010
13
0
Within a directory which has files containing the year in their names, I want to change 2017 to 2018. I tried this:
Code:
ren /n "::^(.*201)7(.*)$" "::\1\x38\2"
but it wants to change, for example, aaa2017bbb.txt to aaa201x38bbb.txt.

The \xnn construct also does not seem to be recognized in a DIR command. For example, this works:
Code:
dir "::^.*2017.*$"
but this doesn't:
Code:
dir "::^.*201\x37.*$"

I'm using Perl regexes. What am I doing wrong?
 
May 20, 2008
11,388
99
Syracuse, NY, USA
I can't explain it, but this works.
Code:
v:\> dir ::.*201\x{37}.*

 Volume in drive V is DATA         Serial number is c007:d3e4
 Directory of  V:\::.*201\x{37}.*

2018-10-22  01:24               0  abc2017.txt
                   0 bytes in 1 file and 0 dirs
       6,741,622,784 bytes free
 
May 23, 2010
13
0
Unfortunately: While it works fine with DIR, as in your example, it does not with REN:
Code:
ren /n "::^(.*201)7(.*)$" "::\1\x{38}\2"
produces a file named aaa201x{38}bbb.txt.

Phoo.
 

ben

Jan 3, 2012
44
6
UK
[Corrected version]

You can enclose the back-reference numbers in braces. Also,, you don't need to include the context of the match.

Code:
C:\tmp> dir /mk ::2017
2018-10-22  09:08               0  aaa2017bbb.txt

C:\tmp> ren ::^(.*)2017(.*) ::\{1}2018\2
C:\tmp\aaa2017bbb.txt -> C:\tmp\aaa2018bbb.txt

C:\tmp> ren ::^(.*)2017 ::\{1}2018
C:\tmp\aaa2017bbb.txt -> C:\tmp\aaa2018bbb.txt

C:\tmp> ren ::2017(.*) ::2018\1
C:\tmp\aaa2017bbb.txt -> C:\tmp\aaa2018bbb.txt

C:\tmp> ren ::2017 ::2018
C:\tmp\aaa2017bbb.txt -> C:\tmp\aaa2018bbb.txt
 
Last edited:
May 23, 2010
13
0
Wow. Cool. That opens up more regex powers than I thought were available in TCC.

But how did you do the renames without using the REN command? That doesn't work for me.
Code:
[D:\foo]echo foo > aaa2017bbb.txt

[D:\foo]dir /a:-d /mk
10/22/2018   2:54               5  aaa2017bbb.txt

[D:\foo]::2017 ::2018
[D:\foo]dir /a:-d /mk
10/22/2018   2:54               5  aaa2017bbb.txt
 

ben

Jan 3, 2012
44
6
UK
Sorry! I had edited out the name of the command. Now corrected.
 
Last edited:
May 23, 2010
13
0
No, I do not want to do that. It makes no sense. I just wondered how you accomplished it in the example you gave above. Or did you simply edit out the lines where you used the REN command?
 
May 20, 2008
11,388
99
Syracuse, NY, USA
Unfortunately: While it works fine with DIR, as in your example, it does not with REN:
Code:
ren /n "::^(.*201)7(.*)$" "::\1\x{38}\2"
produces a file named aaa201x{38}bbb.txt.

Phoo.
Except for the back-references, I think the new name is a literal. It's not treated as a regex.
 
May 23, 2010
13
0
Sorry to resurrect this thread, but I'm still having troubles in the same (or a very similar) vein. Suppose I want to add an extension to all files whose names are wholly alphabetic (A-Z). My directory looks like this:
Code:
12/16/2018   3:05               0                  FILE.exe
12/16/2018   3:05               0                  FIRST
12/16/2018   3:05               0  NOTTHI~1        NOT THIS ONE
12/16/2018   3:05               0                  SECOND
12/16/2018   3:05               0                  TEXT.txt
12/16/2018   3:05               0                  THIRD
So my rename should work on the files named FIRST, SECOND, and THIRD. But the obvious commands (below) do not work:
Code:
ren ::^([a-z]+)$ ::\1.txt
ren "::^([a-z]+)$" "::\1.txt"
ren "::^([a-z]+)$" "::\{1}.txt"
The first one wants to work on all the files (and it succeeds in adding an extension to those files that already have an extension). For the files that should be renamed, all three commands want to rename them to the same name!

As mentioned above, I'm using Perl REs.

So get out the mallets and beat some understanding into my thick skull. Please.
 
Similar threads
Thread starter Title Forum Replies Date
rps Regex problem: \xnn not recognized as a hex character Support 0
D Regex problem Support 17
F %@regex["^-","-a"] returns 0, "^-" =~ "-a" is false (no match) Support 4
JohnQSmith Regex renaming Support 2
vefatica TPIPE: unbalanced escaped quotes in a regex? Support 5
R Regex using ^ Support 2
T Regex engine doesn't recognize native DOS line endings Support 2
P Simple RegEx copy Support 9
samintz WAD Regex Analyzer Support 1
D How to? Use typed envars using regex. Support 3
P Renaming with a RegEx Support 1
R How to? use @everything perl regex Support 2
C v18 regex help please Support 1
C Font of RegEx Analyzer Support 0
mikea How to? Regex match when there shouldn't be (?) Support 18
JohnQSmith Fixed Copying with regex (several issues) Support 7
D Help needed to get a regex to work Support 3
thedave WAD Regex match on \h Support 5
Ville Regex & conditionals Support 9
samintz Regex Rename Support 2
vefatica @REGEX: behavior vs. documentation Support 2
vefatica @REGEX revisited Support 4
vefatica @REGEX question Support 6
vefatica Regex question Support 5
B Regex and Replace Support 6
Stefano Piccardi detecting BOM, FFIND multibyte regex Support 18
dcantor FFIND syntax -- is /E"regex" /X supported? Support 2
P Renaming files with regex. Support 6
B "Fun" with DO and Regex Support 12
P Need to use a regex in a "for" loop. Support 54
Dick Johnson Weird Color Problem Support 8
fishman@panix.com Problem with 27.15 Support 2
M Problem with VSDevCmd.bat in VS 16.7.3 Support 0
R Problem with @INT[ value] in V26 Support 9
M Selecting test "off by one" problem in Take command Support 4
Alpengreis UTF-8 problem in TCC related to Python Support 7
K_Meinhard Small problem in german IDE 26 Support 3
B Problem with color in nested shells Support 1
Joe Caverly Problem creating and switching to a DESKTOP Support 9
vefatica Another popup problem Support 10
Alpengreis ffind dialog (/W) problem Support 4
Alpengreis [TCMD v25.00.24] Small space problem with the DE translation in Prefs-GUI Support 1
Alpengreis [TCMD v25.00.24] Problem with copy and paste and the # char via mouse in TCC Support 6
A Problem with functions @int @decimal and identifying Powershell as a shell. Support 12
B IF command problem in tcexit.btm Support 9
fishman@panix.com Problem at Startup of TCC Support 3
P Problem with SFTP copies Support 7
P Problem with FTP copies Support 10
Jay Sage Problem with Context Menu Copy+Paste+Run Key Assignment Support 7
R Problem with %_do_loop in nested do loops Support 2

Similar threads