Video File Extension in GO
Match common video file extensions: mp4, mov, avi, mkv, webm, m4v, flv, wmv, mpg, mpeg.
Try it in the GO tester →Pattern
regexGO
\.(mp4|mov|avi|mkv|webm|m4v|flv|wmv|mpg|mpeg)$ (flags: i)Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`(?i)\.(mp4|mov|avi|mkv|webm|m4v|flv|wmv|mpg|mpeg)$`)
input := `movie.mp4`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
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.mp4Matches
.mp4
Input
footage.MOVMatches
.MOV
Input
song.mp3No match
—