Regular expressions in commands

Jan 19, 2011
Norman, OK
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.

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
xcmd ren "(.*? .) (.*?)\.doc" "\2, \1.doc"

Caveat emptor, but it works for me. So, here's the alias.
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.
  • Like
Reactions: noahcoad