Tag: regex

Articles and experiments related to regex.

Google Search: find file extension with regex in c#

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.

Read article

C# CSS Classname Regex

I've updated my C# regex for extracting CSS class names to correctly handle URLs in CSS properties like url(someimage.png). The previous version incorrectly matched file extensions. The improved regex uses a negative lookbehind assertion (?<!url\s*\(.*) to prevent matching class names within url() declarations. It now accurately extracts class names, even with variations in spacing within the url() function.

Read article

Answer to CSS Regex Question

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.

Read article

Regex To Get Class Names From CSS 2.0

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.

Read article

CSS C# Token Reader

I'm diving into the official CSS 2.1 specification to build a C# based token reader for CSS parsing. The document itself is quite dense, but it lays out the syntax and provides regular expressions to guide the implementation. This is going to be a challenging but interesting project.

Read article

Google Search: perl c# comparison

This post discusses the differences between Perl and C#. While both languages use semicolons, they differ significantly in object-oriented features, frameworks, semantics, and regular expression handling. C# is strictly object-oriented with a robust framework, while Perl offers more flexibility and built-in regular expressions. The author uses Perl for quick tasks on their Linux server and C# professionally.

Read article

C# Query from Google

This post addresses the C# problem of checking if a string contains a number. Two approaches are suggested: using the Convert class with specific data types like Convert.ToInt16, Convert.ToInt32, Convert.ToFloat, etc., and using regular expressions like ^[0-9]+$ or ^[\d]+$ for whole number strings. The post aims to help C# programmers effectively perform this type of string validation.

Read article

RE: Regex 101 Exercise S2 - Verify a string is a hex number

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.

Read article

Stay in the loop.

I'm trialing a newsletter. Join for monthly insights into web dev, Chrome, and the open web.

alternate_email

Get in touch

Open to chat about Chrome or Web development.

Book a consultation