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
How can I group list of links.
Re: How can I group list of links.
Google: site:autohotkey.com incremental search
Re: How can I group list of links.
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
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: How can I group list of links.
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
}