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.
How to change the domain of a url Topic is solved
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: How to change the domain of a url
Code: Select all
from := "www.somedomain.com/files/sheet1.htm"
ChangeTo := "anotherdomain.co.uk"
MsgBox, % RegExReplace(from, "m`a)^(www.+?)(?=\/)", changeto)
ExitApp
This doesn't cover all cases but its a start for you
-
- Posts: 4389
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: How to change the domain of a url Topic is solved
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)
Re: How to change the domain of a url
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
Re: How to change the domain of a url
Thanks for all these suggestions. @teadrinker second suggestion seems the neatest in my use case. I can complete my project now! Thanks.