There is question by the almost the same name already: What is the best regular expression to check if a string is a valid URL
I don\'t understand this stackoverflow
Here's RFC that you can study: RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax. Section 3.2.2 Host is what you're looking for.
3.2.2 Host
Unfortunately PHP's build-in function filter_var() doesn't support IPv6 syntax: