How can I group list of links.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

How can I group list of links.

19 Nov 2017, 11:39

The link may start with any of those but I want the sorted list to use as a start the letter after them
http://
https://
http://www.
https://www.
www.

And then when the list is sorted to separate the different sites with one line containing |

From

https://autohotkey.com
http://autohotkey.com/boards/viewforum.php?f=5
http://www.google.com
http://www.youtube.com
http://google.com
http://autohotkey.com
http://autohotkey.com/boards/viewforum.php?f=6

to

http://autohotkey.com
https://autohotkey.com
http://autohotkey.com/boards/viewforum.php?f=5
http://autohotkey.com/boards/viewforum.php?f=6
|
http://www.google.com
http://google.com
|
http://www.youtube.com

It's probably with regex but I'm not good with it
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: How can I group list of links.

19 Nov 2017, 13:56

Google: site:autohotkey.com incremental search :?:
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How can I group list of links.

19 Nov 2017, 16:37

Here's an attempt.

Code: Select all

q:: ;sort urls (ignore http/www) (add separator between urls with same domain)
vText = ;continuation section
(
https://autohotkey.com
http://autohotkey.com/boards/viewforum.php?f=5
http://www.google.com
http://www.youtube.com
http://google.com
http://autohotkey.com
http://autohotkey.com/boards/viewforum.php?f=6
)

Sort, vText
Sort, vText, F SortUrls
MsgBox, % vText

VarSetCapacity(vOutput, StrLen(vText)*2)
Loop, Parse, vText, `n, `r
{
	vUrl := A_LoopField
	vDomain := RegExReplace(vUrl, "^(https?://)?(www\.)?|/.*")
	if (A_Index > 1) && !(vDomain = vDomain2)
		vOutput .= "|`r`n" vUrl "`r`n"
	else
		vOutput .= vUrl "`r`n"
	vDomain2 := vDomain
}
Clipboard := vOutput
MsgBox, % vOutput
return

SortUrls(vTextA, vTextB, vOffset)
{
	vTextA := RegExReplace(vTextA, "^(https?://)?(www\.)?")
	vTextB := RegExReplace(vTextB, "^(https?://)?(www\.)?")
	return (vTextA "") > (vTextB) ? 1 : (vTextA "") < (vTextB) ? -1 : -vOffset
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: How can I group list of links.

19 Nov 2017, 18:30

RegExReplace instead of parsing:

Code: Select all

; q:: ;sort urls (ignore http/www) (add separator between urls with same domain)
vText = ;continuation section
(
https://autohotkey.com
http://autohotkey.com/boards/viewforum.php?f=5
http://www.google.com
http://www.youtube.com
http://google.com
http://autohotkey.com
http://autohotkey.com/boards/viewforum.php?f=6
)

Sort, vText
Sort, vText, F SortUrls
;MsgBox, % vText

MsgBox, % vOutput := RegExReplace(vText, "x) ((?:https?://)?(?:www\.)?) (.+?) (\..*?(\R|$))  ((?1) \2 (?3))* (?!$)", "$0|`r`n")
return

SortUrls(vTextA, vTextB, vOffset)
{
   vTextA := RegExReplace(vTextA, "^(https?://)?(www\.)?")
   vTextB := RegExReplace(vTextB, "^(https?://)?(www\.)?")
   return (vTextA "") > (vTextB) ? 1 : (vTextA "") < (vTextB) ? -1 : -vOffset
}
 

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, doanmvu and 365 guests