MP3s are everywhere and back in 2014 I finally had a phone with enough storage to store a decent amount of them. I use MediaMonkey to add high resolution album covers and to rename the files in a predictable format: Artist – Album – # – Title. The only thing I was missing was a simple way of creating a M3U playlist: PowerShell to the rescue!
Yesterday I was working on a bit of code that had to read the XMP meta data from a file. It is not located at a certain position, so I had to scan the file. XMP, being plain XML, can be found by simple string matching. After some searching I’ve found many solutions that read the entire file into memory and perform a regular expression search or a string comparison. That’s not going to work for me, because I have files that are +100MB! So I wrote some code that does a search that performs.
PowerShell runs on .NET and uses the .NET regex engine, but PowerShell adds its own string semantics. Two independent failures can break a capture-group replacement: multiline matching and PowerShell interpolating `$1` before it reaches the regex engine.
As a developer, I love solving common string problems with regular expressions. Sure, they are sometimes hard to read, but you can do so much with such a small expression! It is nice that many languages support them, although it sometimes feels like every language creates its own dialect. Let’s look at the differences between regular expression groups in .NET and JavaScript.