Webflags: gi
URL Validation
Match http and https URLs with optional www prefix, paths, query strings, and fragments.
Try it in RegexProPattern
regexJavaScript
/https?:\/\/(?:www\.)?[\w\-]+(?:\.[\w\-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=%]*/giRaw source: https?:\/\/(?:www\.)?[\w\-]+(?:\.[\w\-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=%]*
How it works
Starts with http:// or https://, optional www., then one or more domain labels separated by dots, followed by any valid URL characters for the path and query.
Examples
Input
https://www.example.comMatches
https://www.example.com
Input
http://api.example.org/v1/users?id=42Matches
http://api.example.org/v1/users?id=42
Input
not a urlNo match
—Common use cases
- Extracting links from text or HTML
- Validating user-submitted URLs
- Web scraping and crawling
- Security scanning for external links