MatchesMimeType🔗

Type: Pattern verification
Check that text conforms to the pattern of MIME type.
text🔗
Text to be checked
Return🔗
True if the text conforms to the pattern

Code

tchar = "[!#$%&'*+\\-.^_`|~0-9a-zA-Z]"
token = f"({tchar})+"
type = f"{token}"
subtype = f"{token}"
ows = "[ \t]*"
obs_text = "[\\x80-\\xff]"
qd_text = f"([\t !#-\\[\\]-~]|{obs_text})"
quoted_pair = f"\\\\([\t !-~]|{obs_text})"
quoted_string = f'"({qd_text}|{quoted_pair})*"'
parameter = f"{token}=({token}|{quoted_string})"
media_type = f"^{type}/{subtype}({ows};{ows}{parameter})*$"

return match(media_type, text) is not None