BytePane

MIME Type Regex Pattern

Validates MIME type format with standard top-level types and subtypes. Used in HTTP headers and file handling.

📁
File & Path
Intermediate
Difficulty
Universal
Language
none
Flags
// Regular Expression
/^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9][a-zA-Z0-9!#$&\-^_.+]*$/

Live Regex Tester

Pattern Breakdown

^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9][a-zA-Z0-9!#$&\-^_.+]*$
Character class [ ]
Group ( )
Quantifier { }
Anchor ^ $
Repetition * + ?
Escape \
Alternation |
Any char .

Code Examples

JavaScript

const regex = /^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9][a-zA-Z0-9!#$&\-^_.+]*$/;
const test = "application/json";
console.log(regex.test(test)); // true

// Extract matches
const matches = test.match(regex);
console.log(matches);

Python

import re

pattern = r'^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9][a-zA-Z0-9!#$&\-^_.+]*$'
test = "application/json"
match = re.search(pattern, test)
print(match)  # Found!

Go

package main

import (
    "fmt"
    "regexp"
)

func main() {
    re := regexp.MustCompile(`^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9][a-zA-Z0-9!#$&\-^_.+]*$`)
    fmt.Println(re.MatchString("application/json")) // true
}

Common Use Cases

Content-Type validationfile upload handlingAPI headers

Match Examples

InputResult
application/jsonMatch
invalid/type/extraNo Match

About the MIME Type Regex

Validates MIME type format with standard top-level types and subtypes. Used in HTTP headers and file handling.

Regular expressions (regex) are powerful pattern matching tools used across virtually all programming languages. The mime type pattern is classified as intermediate difficulty in the file & path category. It works in all major programming languages.

When using this regex, always consider edge cases and test thoroughly with real-world data. Use the interactive tester above to validate the pattern against your specific inputs before deploying to production.

Need More Regex Patterns?

Browse our complete library of 100+ regex patterns with interactive testers.

Frequently Asked Questions

What is the MIME Type regex pattern?

Validates MIME type format with standard top-level types and subtypes. Used in HTTP headers and file handling.

How do I use the MIME Type regex?

Use the pattern /^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9][a-zA-Z0-9!#$&\-^_.+]*$/ in your code. In JavaScript: new RegExp('^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9][a-zA-Z0-9!#$&\-^_.+]*$', ''). Test it above with your own input.

What does this MIME Type regex match?

This pattern matches: "application/json". It does NOT match: "invalid/type/extra". Content-Type validation, file upload handling, API headers.

Is the MIME Type regex beginner-friendly?

This pattern is rated Intermediate. It uses some advanced features like character classes and quantifiers.

What languages support the MIME Type regex?

This pattern works in all major programming languages including JavaScript, Python, Java, C#, Go, Ruby, PHP, and more. Syntax may vary slightly between regex engines.

Can I modify the MIME Type regex for my use case?

Yes! Use the interactive tester above to modify the pattern and test with your own data. Common modifications include making it case-insensitive (add 'i' flag), matching globally (add 'g' flag), or adjusting character classes.

Related Tools