Twitter

Categories

Regular Expression

.NET Framework / C#, Regular Expression, 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.

PowerShell, Regular Expression

Regex Replacement Problem PowerShell: $1?

Madre mia! I’ve been trying to edit an HTML file using PowerShell. I only wanted to eliminate all the spans and paragraphs using regular expressions (would make sense)… and how hard can that be?
Well, it turned out to be pretty hard if you’re used to the replacement syntax of regular .Net expressions! After searching for hours I’ve discovered that $1 can’t be used in the same way as in .Net. Just use ${1}. Ouch!