DD
DevDash

Regex for MIME Type

Regex Pattern

^[a-zA-Z]+\/[a-zA-Z0-9.+-]+$

Standard MIME type format (type/subtype)

Quick Answer

The regex pattern for mime type is `^[a-zA-Z]+\/[a-zA-Z0-9.+-]+$`. Standard MIME type format (type/subtype). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
text/html✓ Matches
application/json✓ Matches
image/svg+xml✓ Matches
application/vnd.api+json✓ Matches
text✗ No match
html✗ No match
text/html/extra✗ No match
/json✗ No match

Code Examples

javascript

const regex = /^[a-zA-Z]+\\/[a-zA-Z0-9.+-]+$/;
const isValid = regex.test(value);

python

import re
pattern = r'^[a-zA-Z]+\/[a-zA-Z0-9.+-]+$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^[a-zA-Z]+\/[a-zA-Z0-9.+-]+$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^[a-zA-Z]+\\/[a-zA-Z0-9.+-]+$/', $value)) {
    echo "valid";
}

java

String pattern = "^[a-zA-Z]+\\/[a-zA-Z0-9.+-]+$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.