Video File Regex

\.(mp4|webm|mov|avi|mkv|flv|wmv)$

Match common video file extensions.

Test This Pattern →

Pattern Breakdown

Understanding the regex pattern \.(mp4|webm|mov|avi|mkv|flv|wmv)$:

  • $ - End of string
  • (...) - Capturing group
  • | - Alternation (OR)

Examples

Input Result Explanation
movie.mp4 ✓ Match MP4 video
clip.webm ✓ Match WebM video

Code Examples

JavaScript

JavaScript
const pattern = /\.(mp4|webm|mov|avi|mkv|flv|wmv)$/;
const text = "movie.mp4";

// Test if string matches
if (pattern.test(text)) {
  console.log("Valid!");
}

// Extract matches
const matches = text.match(pattern);
console.log(matches);

Python

Python
import re

pattern = r'\.(mp4|webm|mov|avi|mkv|flv|wmv)$'
text = "movie.mp4"

# Test if string matches
if re.match(pattern, text):
    print("Valid!")

# Find all matches
matches = re.findall(pattern, text)
print(matches)

PHP

PHP
<?php
$pattern = '/\.(mp4|webm|mov|avi|mkv|flv|wmv)$/';
$text = "movie.mp4";

// Test if string matches
if (preg_match($pattern, $text)) {
    echo "Valid!";
}

// Find all matches
preg_match_all($pattern, $text, $matches);
print_r($matches);
?>

Java

Java
import java.util.regex.*;

String pattern = "\\.(mp4|webm|mov|avi|mkv|flv|wmv)$";
String text = "movie.mp4";

Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(text);

if (m.matches()) {
    System.out.println("Valid!");
}

Use Cases

Common applications: Video upload validation, media servers

Frequently Asked Questions

What is the regex pattern for video file regex?
The regex pattern is: \.(mp4|webm|mov|avi|mkv|flv|wmv)$. Match common video file extensions.
How do I use the video file regex pattern in JavaScript?
In JavaScript: const regex = new RegExp('\\.(mp4|webm|mov|avi|mkv|flv|wmv)$'); or const regex = /\.(mp4|webm|mov|avi|mkv|flv|wmv)$/;
Does this pattern work in Python?
Yes, use: import re; pattern = re.compile(r'\.(mp4|webm|mov|avi|mkv|flv|wmv)$') in Python. Most regex patterns are cross-language compatible.
What are common use cases for video file regex?
Video upload validation, media servers

Related Regex Patterns

More Regex Tools

GetDevUtils offers a suite of developer tools including: