Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

A little help with @REREPLACE

Jun
137
3
I'm rather weak with regular expressions, so please be gentle if I'm asking a rather simple question. What I want to be able to do is to take a file path of the form C:\WIP\E911\Aurora\branches\3.1_FED\Installer\Analytics.ism and change it to C:\WIP\E911\Aurora\main\Installer\Analytics.ism. The string to search will always be of the form <pre>\branches\<some branch>\<post>, and I want to replace the branches\<some branch> with main. So here's what I tried, and it sure looks right to me:

testit=for %f in (%$) echo %f %@rereplace[branches\\[^\\]+\\,main\\,%@quote[%@full[%f]]]

For the alias, I will supply one or more filenames that may be simple filenames, partial paths (such as dot-relative paths, like ..\test\myfile.txt, or maybe just of the form subdir\myfile.txt), or fully qualified paths. Using the %@quote[%@full[%f]] should cover all three of those cases. But my @rereplace isn't doing anything. My output is just the argument supplied followed by its full path, with no replacement having occurred. What do I have wrong?
 
Try doubling the '^'.
Code:
v:\> echo %@rereplace[branches\\[^^\\]+\\,main\\,a\branches\foo\bar]
a\main\bar
 
Thanks, Vince! Can you please explain why I need two up-arrows?
Not 100%. '^' is TCC's escape character. With only one, it's seen as escaping the '\'. Since '\' doesn't need escaping, the "^\" is just turned into '\'. So @REREPLACE sees "[\\]". "^^" means a literal '^', which what you want in the regular expression.

... or something like that.
 
Not 100%. '^' is TCC's escape character. With only one, it's seen as escaping the '\'. Since '\' doesn't need escaping, the "^\" is just turned into '\'. So @REREPLACE sees "[\\]". "^^" means a literal '^', which what you want in the regular expression.

... or something like that.

Of course! I handled the regular expression's escape but completely forgot about TCC's escape. Thanks! That will help me for the next time I do something like this.
 
or you can also do by side-stepping (redirecting) escape char into another less (or least) important char
setdos /e~ or setdos /e` or into any character you think the most rare uses with respect to the scope of characters usage, or you can just disable it for a while with setdos /x-8, then enable it later with setdos /x8
 
or you can also do by side-stepping (redirecting) escape char into another less (or least) important char
setdos /e~ or setdos /e` or into any character you think the most rare uses with respect to the scope of characters usage, or you can just disable it for a while with setdos /x-8, then enable it later with setdos /x8

Certainly a valid alternative. Thank you!
 
Back
Top
[FOX] Ultimate Translator
Translate