A regular expression to match all valid URLs with port numbers, hashes(#), and parameters (&).
/^(((ht|f)tps?):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?$/
If you’re looking for a regex that matches a URL with a port number:
/^((ht|f)tps?:\/\/)?[\w-]+(\.[\w-]+)+:\d{1,5}\/?$/
URL Examples:
- https://regexpattern.com/
- https://regexpattern.com/#/a=1&b=2
- https://regexpattern.com/:8080
- ftps://regexpattern.com/
See Also:
- IP Address (V6) With Port Regular Expression
- IP Address (V4) With Port Regular Expression
- Subnet Mask Regular Expression
- Domain Name Regular Expression
- Regular Expression To Match All URLs In Text
- Regex To Match One Parameter In URL Query String
- Regex To Extract Domain Name From URL
- DNS Hostname Regular Expression
- Regex To Match All Parameters In A URL
- Regex To Match The Last Path (Segment) Of A URL
- Regex To Match Markdown-style URL Links