Title |
Test
Find
Pattern Title
|
Expression |
^(?<toplevel>[a-z]+) # Matches the top level MIME type, e.g. 'text'
# in 'text/html'
/(?<subtype>[a-z]+) # Matches the sub type, e.g. 'html' in 'text/html'
(\+(?<formattype>[a-z]+))? # Matches the format type, e.g. 'xml' in
# 'application/xhtml+xml'
# (Optional part of the MIME type)
(; *?charset="?(?<charset>[a-z0-9\-]+)"?)?$ # matches the 'charset'
# parameter in the MIME type, e.g. 'iso-8859-1'
# in 'text/html; charset=iso-8859-1'
# (Optional part of the MIME type) |
Description |
Matches MIME Media Types, often to be seen in HTTP
'Content-Type' headers. Extracts the top level type, sub type, format type and charset parameter and assigns them to their respective group in the expression. |
Matches |
text/html | application/xhtml+xml |
Non-Matches |
text |
Author |
Rating:
Not yet rated.
Asbjørn Ulsberg
|
Source |
|
Your Rating |
|
Title: Should match 'charset' as well
Name: Asbjørn Ulsberg
Date: 7/20/2004 10:48:44 AM
Comment:
Though it's not mentioned as a matching sample, e.g. 'text/html; charset=iso-8859-1' should also be matched by the expression. It works well with the .NET framework, at least. Here's a one-line version of the expression as well:
^(?<toplevel>[a-z]+)/(?<subtype>[a-z]+)(\+(?<formattype>[a-z]+))?(; *?charset=""?(?<charset>[a-z0-9\-]+)""?)?$
And here's one without the group-naming:
^([a-z]+)/([a-z]+)(\+([a-z]+))?(; *?charset=""?([a-z0-9\-]+)""?)?$