URL Validation
Match http and https URLs with optional www prefix, paths, query strings, and fragments.
Try it in RegexPro →Available in
Pattern
https?:\/\/(?:www\.)?[\w\-]+(?:\.[\w\-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=%]* (flags: gi)Raw source: https?:\/\/(?:www\.)?[\w\-]+(?:\.[\w\-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=%]*
How it works
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
Related patterns
Twitter / X URL
WebMatch Twitter/X profile and status URLs, capturing the handle and (optional) tweet ID.
GitHub Repository URL
WebMatch GitHub repository URLs and capture the owner and repo segments.
LinkedIn Profile URL
WebMatch LinkedIn profile URLs and capture the profile slug.
URL Query String
WebExtract the query string portion of a URL (everything between `?` and `#` or end-of-string).
Related concepts
Regex Flags in JavaScript: g, i, m, s, u, y
ConceptFlags modify regex behavior globally. g enables global matching, i makes it case-insensitive, m changes anchor behavior, s dots match newlines, u enables Unicode, y is sticky.
How to Extract URLs from Text with Regex
How-toUse a permissive URL pattern with the g flag and String.matchAll. A practical regex accepts http/https, optional www, and common URL characters.