JavaScript / ECMAScript

Video File Extension in JS

Match common video file extensions: mp4, mov, avi, mkv, webm, m4v, flv, wmv, mpg, mpeg.

Try it in the JS tester →

Pattern

regexJS
\.(mp4|mov|avi|mkv|webm|m4v|flv|wmv|mpg|mpeg)$   (flags: i)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("\\.(mp4|mov|avi|mkv|webm|m4v|flv|wmv|mpg|mpeg)$", "i");
const input = "movie.mp4";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

\. matches the literal dot. The alternation covers the most common video container formats. The trailing $ anchors to end-of-string so we don't match `.mp4` mid-filename. The i flag makes matching case-insensitive (.MOV, .Mp4, etc.).

Examples

Input

movie.mp4

Matches

  • .mp4

Input

footage.MOV

Matches

  • .MOV

Input

song.mp3

No match

Same pattern, other engines

← Back to Video File Extension overview (all engines)