Skip to content

Instantly share code, notes, and snippets.

View argentini's full-sized avatar

Michael Argentini argentini

View GitHub Profile
@argentini
argentini / dotnet-css-minifier.cs
Last active February 27, 2024 00:02
Pure dotnet (.NET) C# CSS Minifier - Minify CSS using compiled Regex
#region Compiled CSS Regex; Should be Singletons
public Regex SelectCssComments { get; } = new (@"\/\*.*?\*\/", RegexOptions.Compiled); // Select comment blocks
public Regex SelectCssLineBreaks { get; } = new (@"[\n\r]+\s*", RegexOptions.Compiled); // Select line breaks and subsequent space
// Ensure content property values use quotation marks
public Regex SelectCssContentValueWithApostrophes { get; } = new (@"content:\s*'([^']*)';", RegexOptions.Compiled); // Select content properties using apostrophes
public Regex SelectCssContentValueWithSpacePrefix { get; } = new ("""content:\s{1,}"([^\"]*)";""", RegexOptions.Compiled); Select content properties with space between the name and value
public Regex SelectCssEmptyContentValueWithSpacePrefix { get; } = new ("""content:\s*"";""", RegexOptions.Compiled); // Select empty content properties