Welcome!

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

SignUp Now!

Regular expressions in commands

Jan
616
15
Copied from another thread.

OK. After quite a bit of tweaking and massaging, I finally got a generic regex command created using Vincent Fatica's 4utils plugin. I've only tried it using COPY and REN since that's where I needed it, but I'm sure it'll work on other commands. Just remember, it doesn't do paths.

Usage:
Code:
xcmd <command> <input> <output>

For instance... if I have a bunch of files named in the style of "Firstname X Lastname.doc" and want to rename them in the style of "Lastname, Firstname X.doc", then the command would be
Code:
xcmd ren "(.*? .) (.*?)\.doc" "\2, \1.doc"

Caveat emptor, but it works for me. So, here's the alias.
Code:
xcmd=for /w %i in (%@quote[::%@unquote[%2]]) %1 %@quote[%@filename[%i]] %@quote[%@xreplace[%@quote[%@unquote[%2]],%@quote[%@unquote[%3]],%@quote[%@filename[%i]]]]

Remember, you can't just copy, paste, and run the alias at the TCC prompt unless you double all the % signs first.
 
Back
Top