Regex, The (2008)
So I have this list of movies I’ve seen - it’s a plain text file accumulated from roughly the steps outlined here - let’s say I just saw the movie “Cloverfield” on DVD…
- Fire up Opera
- Type g imdb cloverfield
- Click the first link in the results to go to the IMDb entry for that movie (to verify that it’s indeed the one I saw)
- Select the movie’s title on that page
- Hit ⌃ ⌥ SPACE to open selected text in Quicksilver
- Type AP to get the command “Append to file…”
- Hit TAB and hold F (for “filmlisten.txt”)
That’s it — the movie has been added to my list.
The problem is: At some point in time between the inauguration of my sacred file and now, they (IMDb) changed the format of the title for movies starting with “The …”. You see, before (back in the day, once upon a time, etc.) — Kubrick’s 1980 movie was listed as Shining, The (1980) whereas now, it’s listed as The Shining (1980).
Being so darn picky about that, my textfile was a mess… you see, I like a certain kind of order in the universe (at least in my part of it) so once in while, I’d follow that last step with an additional ⌃ SPACE + ↩ to open the textfile in TextMate, then F5 to sort the lines alphabetically.
But alphabetically just wasn’t good enough anymore, because some movies we’re listed in the old format while others were in the new one. And there were just about a couple of hundred titles pending a fix so I needed a command of some sort — and no, doing a simple Find & Replace wouldn’t be able to fix this.
Enter Regex — Regular Expression(s)
A Regular Expression is the perfect solution here, because you can easily match something, store it and then come back and fetch it again. TextMate lets you do this in the Find & Replace dialog, so I hammered this in:
- and there you have it. All titles properly titled and order has once again been restored to The Galaxy.