Video URL Regex
Matches an absolute HTTP or HTTPS URL that ends in a common video file extension, with an optional query string.
Regex Pattern
^https?:\/\/\S+\.(?:mp4|webm|mov|avi|mkv|flv|wmv)(?:\?\S*)?$Default flags: i
Pattern Breakdown
Hover over a token to see what it does.
| Token | Meaning |
|---|---|
| ^ | Anchors the match to the start of the string |
| https? | Matches http or https |
| :\/\/ | Literal :// scheme separator |
| \S+ | One or more non-whitespace characters making up the host and path |
| \. | Literal dot before the file extension |
| (?:mp4|webm|mov|avi|mkv|flv|wmv) | Non-capturing group of allowed video extensions |
| (?:\?\S*)? | Optional query string starting with ? |
| $ | Anchors the match to the end of the string |
Detailed Explanation
What it does
This pattern validates that a string is a full HTTP(S) URL whose path ends in one of the common video container extensions, optionally followed by a query string such as a signed access token or playback parameter.
Why it works
The greedy \S+ consumes as much of the URL as possible before backtracking to let the literal dot and extension alternation match at the very end of the path, ahead of any optional query string. Anchoring the whole string with ^ and $, combined with the case-insensitive flag, guarantees the entire input is a well-formed URL ending in a recognized video extension regardless of casing.
Common use cases
- Filtering scraped links to only those pointing at downloadable or streamable video files
- Validating a video upload URL field before queuing a transcoding job
- Deciding whether to render a <video> element instead of a generic link preview
- Building a media crawler that separates video assets from other content types
Edge cases
- Uppercase extensions like .MP4 or .MOV are matched because of the case-insensitive i flag
- Query strings such as ?token=abc123 after the extension are accepted without breaking the match
- A trailing slash after the extension, like video.mp4/, is intentionally rejected since the extension must be the final path segment
- URLs with no scheme, like example.com/clip.mp4, are rejected because http:// or https:// is required
- Adaptive streaming manifests like .m3u8 or .mpd are not matched since they aren't in the extension list
Limitations
- Relies purely on the file extension and does not verify the actual content type or codec of the resource
- Does not cover streaming manifest formats such as HLS (.m3u8) or DASH (.mpd) unless added to the alternation
- Cannot detect videos served without an extension, such as dynamically generated streaming endpoints
Interactive Tester
Edit the pattern or text below — matching runs live in your browser.
Test Cases
Editable — add your own inputs to see if they pass.
| Input | Expected | Result | |
|---|---|---|---|
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass |
Language Variants
Production-ready examples in 12 languages.
const videoUrlRegex = /^https?:\/\/\S+\.(?:mp4|webm|mov|avi|mkv|flv|wmv)(?:\?\S*)?$/i;
console.log(videoUrlRegex.test('https://example.com/movie.webm')); // trueCommon Mistakes
Forgetting the case-insensitive flag, so uppercase extensions like .MP4 fail validation
Fix: Add the i flag (or an equivalent case-insensitive compile option) since extensions are commonly written in either case
Allowing the extension to appear anywhere in the URL instead of only at the end, causing false positives like example.com/mp4-guide/index.html
Fix: Require the extension to be immediately followed by the end of the string or a query string using $ and an optional (?:\?\S*)?
Assuming this pattern also matches streaming manifests like .m3u8 or .mpd
Fix: Add those extensions explicitly to the alternation if adaptive streaming URLs need to be recognized too
Performance Notes
- \S+ is greedy and will backtrack character by character to find the extension, which is fine for typical URL lengths but can be slow on extremely long, dot-free strings
- Anchoring with ^ and $ prevents unnecessary scanning across the whole input for a match
- The extension alternation is checked as a fixed set of short literals, which regex engines optimize well compared to a broader wildcard
Browser Compatibility
| Engine | Supported | Notes |
|---|---|---|
| Chrome | Yes | — |
| Firefox | Yes | — |
| Safari | Yes | — |
| Edge | Yes | — |
| Node.js | Yes | — |