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]*'
obsText = '[\\x80-\\xff]'
qdText = (
    f'([\t !#-\\[\\]-~]|{obsText})'
)
quotedPair = (
    f'\\\\([\t !-~]|{obsText})'
)
quotedString = (
    f'"({qdText}|{quotedPair})*"'
)
parameter = (
    f'{token}=({token}|{quotedString})'
)
mediaType = (
    f'^{type}/{subtype}({ows};{ows}{parameter})*$'
)
return match(
    mediaType,
    text
) is not None