Regular Expressions

Regular Expressions

A regular expression (shortened as regex or regexp; also referred to as rational expression) is a sequence of characters that define a search pattern. Usually such patterns are used by string searching algorithms for “find” or “find and replace” operations on strings, or for input validation. It is a technique developed in theoretical computer science and formal language theory.

Solving Google Prettify Excessive DOM Size
Solving Google Prettify Excessive DOM Size
JavaScript, Regular Expressions

Solving Google Prettify Excessive DOM Size

Lately I’ve been tinkering around with my blog to see if I could get a better score in Google Web Vitals. The “Avoid Excessive DOM Size” attracted my attention. The details showed that my code fields were to blame. I use Google Prettify as it is lightweight and does a pretty good job, but… it renders way too much span elements. Let’s see if we can make it spit out less.

How to scrape a photo from a Twitter Photo URL with C#
How to scrape a photo from a Twitter Photo URL with C#
.NET Framework / C#, Regular Expressions, Twitter

How to scrape a photo from a Twitter Photo URL with C#

Twitter uses its url shortener to place photo’s in Tweets. I’ve tried processing these URLs in the browser, but cross site scripting measures prevented me from processing the result with jQuery.

I decided to resolve it in C# (as I’m using ASP.Net). The following script leverages a WebClient and a regular expression to extract the photo URL from the shortened URL. This code could be added to a handler or a webservice that can be called from script.

Regular Expression Groups in PowerShell (for .NET people)
Regular Expression Groups in PowerShell (for .NET people)
.NET / C#, PowerShell, Regular Expressions

Regular Expression Groups in PowerShell (for .NET people)

PowerShell is very similar to .NET, so it is no surprise that it is very popular with .NET developers. It is a language for writing scripts, so you might encounter some unexpected situations. I had this experience when I tried to parse some HTML with PowerShell: I could not get the replacement with regular expression groups to work! It turned out that my .NET knowledge was working against me…

Regular Expression Groups: .NET vs JavaScript
Regular Expression Groups: .NET vs JavaScript
.NET Core / C#, JavaScript, Regular Expressions

Regular Expression Groups: .NET vs JavaScript

As a developer, I love to solve common string problems with regular expression. Sure, they are sometimes hard to read, but you can do so much with such a small expression! It is nice that many languages have support for them, but sometimes it feels like every language creates its own dialect. Let’s look at the difference between regular expression groups in .NET and JavaScript.