This post addresses a common search query: how to find file extensions using regular expressions in C#. I provide several regex examples for this purpose, including variations for finding extensions only at the end of a string and for specifically finding three-letter extensions.
In a previous post, I shared a regular expression for extracting CSS class names, and a reader asked for clarification. This post addresses the question with a corrected regex and C# code example using Regex.Split and Regex.Match. The regex is designed to capture class names from CSS, even those containing escaped characters, and the example code demonstrates splitting a CSS string by class names and suggests using Regex.Match for obtaining the names themselves.
As part of my ongoing project to build a CSS 2.0 parser in C#, I've developed a regular expression based on the CSS 2.0 specification to extract class names from CSS files. This regex is a step towards creating a complete CSS 2.0 parser, and I plan to develop more regular expressions for other CSS elements in the coming days. Check out my related side project about creating a CSS 2.0 parser in C# for more context.
In a previous post about verifying a hex number string with regex, there was a slight error. The regex should have been ^[A-Fa-f0-9]+$. A further refinement to prevent leading zeros (except for the number zero itself) would look like this: ^[A-Fa-f1-9][A-Fa-f0-9]*$.
This blog post discusses a regex exercise to verify if a string is a hexadecimal number. The proposed solution is ^[A-Fa-f0-9]*$, which matches any combination of hexadecimal digits (0-9 and a-f, case-insensitive). The author acknowledges that this regex allows starting a number with 0, which might not be desirable.