Add space after a subdomain in an url. How? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
KilliK
Posts: 224
Joined: 10 Mar 2016, 21:19

Add space after a subdomain in an url. How?

17 Mar 2019, 21:04

Hello.
Let's say I have thesel urls:

Code: Select all

https://www.test.com/
http://test.co.uk/jpg.png
https://pbs.test.gr/xxx/xxx.jpg
How do I add a space between the subdomain ( test in this case) and the . that follows it, so that they look like this:

Code: Select all

https://www.test .com/
http://test .co.uk/jpg.png
https://pbs.test .gr/xxx/xxx.jpg
I am trying to do it with StrReplace but with no results. I think I need to use RegexMatch but I dont know how to do it.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 00:45

I hate rude people
Last edited by IMEime on 18 Mar 2019, 08:01, edited 1 time in total.
KilliK
Posts: 224
Joined: 10 Mar 2016, 21:19

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 06:26

But this only works if you already know the subdomain. Maybe I wasnt clear, but the subdomain is supposed to be random from random urls.
teadrinker
Posts: 1303
Joined: 29 Mar 2015, 09:41
Contact:

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 06:44

Hi

Code: Select all

urls =
(
https://www.test.com/
http://test.co.uk/jpg.png
https://pbs.test.gr/xxx/xxx.jpg
)

MsgBox, % RegExReplace(urls, "m`a)^https?://(?:www.)?\K(.+?)(?=\.\w+/)", "$1 ")
KilliK
Posts: 224
Joined: 10 Mar 2016, 21:19

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 06:59

you are magnificent, thank you very much.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 08:01

your attitude is the magnificent....
teadrinker
Posts: 1303
Joined: 29 Mar 2015, 09:41
Contact:

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 08:24

Easier:

Code: Select all

RegExReplace(urls, "m`a)^(https?://.+?)(?=\.\w+/)", "$1 ")
User avatar
sinkfaze
Posts: 614
Joined: 01 Oct 2013, 08:01

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 08:41

@IMEime

You're about to take another vacation from these forums. Cool it.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 08:55

@sinfaze
yes
I am considering a month or two off

Thanks for the kind tip
KilliK
Posts: 224
Joined: 10 Mar 2016, 21:19

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 10:06

teadrinker wrote:
18 Mar 2019, 08:24
Easier:

Code: Select all

RegExReplace(urls, "m`a)^(https?://.+?)(?=\.\w+/)", "$1 ")
thanx, but I just noticed something which eluded me the first time. The space is not added correctly to the first dot after the subdomain name, if the domain has two dots.

for example, these urls:

Code: Select all

http://www.test.co.uk/jpg.png
http://test.co.uk/jpg.png
give:

Code: Select all

http://www.test.co .uk/jpg.png
http://test.co .uk/jpg.png
where it should be:

Code: Select all

http://www.test .co.uk/jpg.png
http://test .co.uk/jpg.png
This happens with both instaces of your code.
User avatar
sinkfaze
Posts: 614
Joined: 01 Oct 2013, 08:01

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 10:37

KilliK wrote:
17 Mar 2019, 21:04
Hello.
Let's say I have thesel urls:

Code: Select all

https://www.test.com/
http://test.co.uk/jpg.png
https://pbs.test.gr/xxx/xxx.jpg
How do I add a space between the subdomain ( test in this case) and the . that follows it, so that they look like this:

Code: Select all

https://www.test .com/
http://test .co.uk/jpg.png
https://pbs.test .gr/xxx/xxx.jpg
I am trying to do it with StrReplace but with no results. I think I need to use RegexMatch but I dont know how to do it.
Only one of your above examples has what I would think of as a subdomain, https://pbs.test.gr/xxx/xxx.jpg. It looks more like you're trying to split the second/top level domains from the domain name?
teadrinker
Posts: 1303
Joined: 29 Mar 2015, 09:41
Contact:

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 10:52

KilliK wrote: that they look like this:

Code: Select all

https://pbs.test .gr/xxx/xxx.jpg
KilliK wrote: where it should be

Code: Select all

http://www.test .co.uk/jpg.png
How the script can know what the variant is true? Why not like this: https://pbs .test.gr/xxx/xxx.jpg ?
KilliK
Posts: 224
Joined: 10 Mar 2016, 21:19

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 11:25

teadrinker wrote:
18 Mar 2019, 10:52
....
you are right. and i think turning all the dots between // and the first / will suffice for my situation.

Let me explain the problem. Some Disqus forums dont allow urls in your posts. Otherwise they will auto-delete them. But sometimes I need to add urls for reference during my conversations. After some testing, the best way to circumvent this, is to add spaces in the domain/subdomain part of the url. I want to do this automatically with AHK, by turning this:

Code: Select all

https://a.test.b.c/x/zzz.jpg
into this

Code: Select all

https:// a .test .b .c/x/zzz.jpg
I tried to use StrReplace, but it adds spaces to all the dots in the url. That's why I thought that RegExReplace must be a better solution and I came here for help, since regex is a nightmare for me to handle. :oops:
teadrinker
Posts: 1303
Joined: 29 Mar 2015, 09:41
Contact:

Re: Add space after a subdomain in an url. How?  Topic is solved

18 Mar 2019, 13:47

If you need to change only one url:

Code: Select all

url = https://a.test.b.c/x/zzz.jpg
MsgBox, % RegExReplace(url, "\.(?!\w+$)|(?<=//).", " $0")
; or
MsgBox, % RegExReplace(url, "[^/:](?=/)(*COMMIT)(*FAIL)|(\.|(?<=//).)", " $1")
If all together at once, I did not find one-string solution.

Code: Select all

urls =
(
https://www.test.com/
http://test.co.uk/jpg.png
https://pbs.test.gr/xxx/xxx.jpg
)
Loop, parse, urls, `n, `r
   newUrls .= RegExReplace(A_LoopField, "[^/:](?=/)(*COMMIT)(*FAIL)|(\.|(?<=//).)", " $1") . "`r`n"
MsgBox, % RTrim(newUrls, "`n`r")
KilliK
Posts: 224
Joined: 10 Mar 2016, 21:19

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 16:47

Your code is excellent, it does the job perfectly. thank you again for all your help.
electrone77
Posts: 6
Joined: 16 Mar 2019, 12:30

Re: Add space after a subdomain in an url. How?

18 Mar 2019, 18:23

hey, here's my 2 cents. kinda :offtopic: since question is already answered :angel:

Code: Select all

urls =
(
https www.test.com /  Broken Link for safety
http test.co.uk /jpg.png  Broken Link for safety
https pbs.test.gr /xxx/xxx.jpg  Broken Link for safety
)

msgbox % regexreplace(urls, "m`a)(https?://(www\.|pbs\.)?.*?)\.","$1 .")
or if you encounter other than www/pbs (has to be 3 letters but won't work if the domain name is also 3 letters):

Code: Select all

regexreplace(urls, "m`a)(https?://(\w{3}\.)?.*?)\.","$1 .")

Return to “Ask For Help”

Who is online

Users browsing this forum: DaveF, hasantr, Helgef, Odlanir, Rohwedder, swagfag, WantToKnow and 368 guests