Replacing backslashes with forwardslashes through the REGEXP argument stopped working

A few days I had set up three Opus hotkeys on my system:

Copy Source path to the clipboard, with forward slashes:

@nofilenamequoting
clipboard set {sourcepath REGEXP (.*)\\(.*)# \1/\2}

Copy destination path to the clipboard, with forward slashes:

@nofilenamequoting
clipboard set {destpath REGEXP (.*)\\(.*)# \1/\2}

Copy selection paths to the clipboard, with forward slashed:

@nofilenamequoting
Clipboard COPYNAMES REGEXP (.*)\\(.*)# \1/\2

And were working fine. Today I discover only the last one is indeed working (Copy selection paths to the clipboard, with forward slashed). I could have sworn they were all working just a few days ago.

Today I tried fixing them but no matter what they simply will not work. Only the following format works

clipboard set {sourcepath}

What could I be doing wrong?

Any help would be greatly appreciated!

Look at the code for your first two commands. The } that should be after {sourcepath and {destpath is instead at the end of the lines.

1 Like

Thanks for the help Leo :]
I made the erroneous assumption that I had to insert the REGEXP inside the braces. After reading your comment, all that accomplishes is that the literal string {sourcepath REGEXP (.*)\\(.*)# \1/\2} is inserted in to the Clipboard.

I tried your suggestion:

@nofilenamequoting
clipboard set {sourcepath} REGEXP (.*)\\(.*)# \1/\2

This inserts the {sourcepath} and the string REGEXP (.*)\\(.*)# \1/\2 into my clipboard. So if the source was c:\temp, my clipboard would be:

C:\Temp\ REGEXP (.*)\\(.*)# \1/\2

The backslashes are also present.

Hmm, I think the Clipboard command's REGEX argument only works with COPYNAMES, not when supplying the string yourself.

In theory, the new ability to apply regex to {file} and similar codes could be used here, but that isn't hooked up for {sourcepath} yet, which I've just noticed. Have added that to our to-do list.

If you're using Opus 13, the new Evaluator lets you do this in a nice way:

Clipboard SET {=RegEx(source,"(.*)\\(.*)#","\1/\2")=}

In Opus 12, it could be done with a little script code. Shout if you need that.

1 Like

I decided to go with standard backslash paths in Opus and replace the backslashes with forward slashes in AutoHotkey.

Cheers for the help.

As excited as I am for Opus 13 I have been hesitant to switch to its beta as I dont want a critical script, Add multiple filters and tags to files using ADS, to break.

By the way I would love to try the 13 beta. Do you think the script I linked would work in it, and for the eventual Opus 13 public release version?

There's no reason to think it wouldn't work.

(And, if it doesn't work, the only way it would ever get fixed is if someone tries it, finds out, and tells us. But it should work as we try not to break things.)

1 Like

This is good to know. I will try out Opus 13 then!
Thank you.