How to change the domain of a url Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
thegrove
Posts: 11
Joined: 16 Jun 2020, 09:43

How to change the domain of a url

16 Jun 2020, 10:02

I want to be able to change the domain part of a URL by capturing what's in the clipboard, changing it and opening the new URL in a new browser tab.

Example:

https www .somedomain.com/files/sheet1.htm
becomes
https www .anotherdomain.co.uk/files/sheet1.htm

I have been looking at some scripts to extract the parts of the URL but cannot work out how to recompile the parts into the new url. Or is there some smart regex way of doing this in one line of code? i.e. append everything after the first single "/" to my new domain?

Thanks.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: How to change the domain of a url

16 Jun 2020, 10:42

Code: Select all

from := "www.somedomain.com/files/sheet1.htm"
ChangeTo := "anotherdomain.co.uk"
MsgBox, % RegExReplace(from, "m`a)^(www.+?)(?=\/)", changeto)

ExitApp
Its based on @teadrinker code here https://www.autohotkey.com/boards/viewtopic.php?t=62842

This doesn't cover all cases but its a start for you
teadrinker
Posts: 4389
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to change the domain of a url  Topic is solved

16 Jun 2020, 10:53

Perhaps this is right:

Code: Select all

url := "https://www.somedomain.com/files/sheet1.htm"
newDomain := "anotherdomain.co.uk"
MsgBox, % RegExReplace(url, "//(www\.)?\K[^/]+", newDomain)
; or
MsgBox, % RegExReplace(url, "//\K[^/]+", newDomain)
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How to change the domain of a url

16 Jun 2020, 11:18

Code: Select all

!c::        ; press ctrl+c
     Send ^c    ; copy path to clipboard
     MsgBox % "chrome.exe " StrReplace(clipboard, "https://www.somedomain.com/","https://www.anotherdomain.co.uk/") ; replace 'MsgBox' with 'Run'
     Return
thegrove
Posts: 11
Joined: 16 Jun 2020, 09:43

Re: How to change the domain of a url

17 Jun 2020, 02:27

Thanks for all these suggestions. @teadrinker second suggestion seems the neatest in my use case. I can complete my project now! Thanks.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, j4byers and 118 guests