1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Regular expressions in commands

Discussion in 'T&T - Aliases' started by JohnQSmith, Mar 14, 2012.

  1. JohnQSmith

    Jan 19, 2011
    Likes Received:
    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.
    noahcoad likes this.

Share This Page