I run a Linux emulator (or subsystem) under Windows 10, and sometimes I need to past Windows paths in the Linux console. Windows paths use backslashes \ to separate directories whereas Linux paths use forward slashes / instead.

To avoid having to replace the \ with / manually, I have tried using an AHK script to do the replacement on any path that I copy, but it doesn't want to work.

This is my script (I have marked in the code ##works until here## the furthest point until where it seems to be working):

^+7:: ; Ctrl+Shift+7 (/)

;Empty the Clipboard.
    Clipboard =
;Copy the select text to the Clipboard.
    SendInput, ^c
;Wait for the Clipboard to fill.

;Perform the RegEx find and replace operation,
;where the needle is what we want to replace.
    haystack := Clipboard
    needle := "\"
    replacement := "/"
    result := RegExReplace(haystack, needle, replacement)

;Empty the Clipboard
    Clipboard =
;Copy the result to the Clipboard.
    Clipboard := result
;##works until here##
;Wait for the Clipboard to fill.

;-- Optional: --
;Send (paste) the contents of the new Clipboard.
    SendInput, %Clipboard%


Thanks in advance for any tips.

up vote 0 down vote accepted

It seems the backslash needs to be escaped to be recognized by RegExReplace, like this:

needle := "\\"

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.