`
(?(DEFINE)
(?<PROTOCOL>[^:/#?\s]+://)
(?<LOGIN>[^:@/#?\s]+(?::[^@/#?\s]+)?@)
(?<TEXT_DOMAIN>[^./#?\s-:]+(?:-[^./#?\s-:]+)?\.)
(?<IP_DOMAIN>
(?&NOT_RESERVED_IP)
(?:
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.
){3}
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
)
(?<NOT_RESERVED_IP>
(?!(?:1?0|224)(?:\.\d{1,3}){3}|
(?:192\.168|172\.16)(?:\.\d{1,3}){2}
)
)
(?<TLD>[^/#?\s.\d:-]+)
(?<PORT>:\d{1,4})
(?<PATH>/(?:[^/\s&#?]*/?)+)
(?<QUERY>
\?
(?:
[^\s=]+(?:=[^&\s]*)?
(?:&[^\s=]+(?:=[^&\s]*)?)*
)?
)
(?<HASH>\#.*)
)
^
(?&PROTOCOL)
(?&LOGIN)?
(?:(?&TEXT_DOMAIN)+(?&TLD)|(?&IP_DOMAIN))
(?&PORT)?