-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathURLParser.ahk
36 lines (32 loc) · 906 Bytes
/
URLParser.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class URLParser {
Protocol := ""
Domain := ""
Port := ""
Path := ""
Query := ""
Hash := ""
Username := ""
Password := ""
__New(url) {
this.ParseURL(url)
}
ParseURL(url) {
regex := "^(?<Protocol>https?|ftp)://(?:(?<Username>[^:]+)(?::(?<Password>[^@]+))?@)?(?<Domain>(?:[\w-]+\.)+\w\w+)(?::(?<Port>\d+))?/?(?<Path>(?:[^/?# ]*/?)+)?(?:\?(?<Query>[^#]+)?)?(?:#(?<Hash>.+)?)?$"
if (RegExMatch(url, regex, &match)) {
this.Protocol := match.Protocol
this.Username := match.Username
this.Password := match.Password
this.Domain := match.Domain
this.Port := match.Port
this.Path := match.Path
this.Query := match.Query
this.Hash := match.Hash
}
}
}
; Usage:
; url := "https://www.google.com/search?q=github"
; parser := URLParser(url)
; MsgBox(parser.Protocol) ; Output: http
; MsgBox(parser.Domain) ; Output: www.google.com
; MsgBox(parser.Query) ; Output: q=github