This regex splits an http or https url into its parts.
^(?:(?:(?:(http[s]?):\/\/)(?:([a-zA-Z0-9]+)?\.)?([^:\/\s\?]+\.+[^:\/\s\?]+))?(?:((?:\/[^\/\s]+)*\/)?(?:([\w\-\.]+[^#?\s]+))?)?(#[^#?\s]+)?(?:\?+([^\.\s$]+)?)?)$
- Whole match
- Protocol
- Subdomain
- Domain
- Path
- File
- Anchor id (That #scrollto things)
- Parameters
http://sub.domain.de/here/is/the/file.php#home?test=1
will turn to:
http
sub
domain.de
/here/is/the/
file.php
#home
test=1
not existent parts will lead to empty groups. Have fun using this :-)