using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?<type>\w*)\/(?<tree>([\w\-]+\.)+)?(?<subtype>[\w\-]+)(\+(?<suffix>[\w\-\.]+))?(; (?<parameter>[\w+-\.=]+))?";
string input = @"text/html; charset=UTF-8
application/x-executable
application/graphql
application/javascript
application/json
application/ld+json
application/msword
application/pdf
application/sql
application/vnd.api+json
application/vnd.ms-excel
application/vnd.ms-powerpoint
application/vnd.oasis.opendocument.text
application/vnd.openxmlformats-officedocument.presentationml.presentation
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/x-www-form-urlencoded
application/xml
application/zip
application/zstd
audio/mpeg
audio/ogg
image/gif
image/apng
image/flif
image/webp
image/x-mng
image/jpeg
image/png
multipart/form-data
text/css
text/csv
text/html
text/php
text/plain
text/xml";
foreach (Match m in Regex.Matches(input, pattern))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx