So I do this peculiar thing, where I prepend the author’s initials to the title of every book I add to Calibre.1 2
And all these years, I’ve just been manually editing the metadata, everytime I added a book, and changing the titles to what I want.
It’s not a problem if it’s just one book, but I normally tend to go hogwild with authors, normally buying out / downloading all their work.
And now that I’ve learnt the basics of the hammer called regex, I wanted to see, you guessed it, if there was a way to quickly do this using regular expressions in Caliber, which has inbuilt support for regexes.
A quick look through the documentation led me to the search and replace page, which explains really pretty well … well, how search and replace works :)
So what did I need to do?
I needed to take the initial character of the title of any book.
And then replace it with author initials + that character
So here’s the Calibre search and replace box when I choose to edit the metadata for multiple books.
I choose Regular expression as my MO and I choose the title field to work with.
You can see the titles of the books, I chose below3
Then, in the “Search for:” box, I go looking for a single character at the beginning of the title.
With regex I express that as a ^.
I’ve surrounded that pattern with ()
brackets to tell regex to remember what it matched.
You’ll see that I’ve matched the character succcesfully and the “A” from A Journey … and the “T” from Twenty Thousand … are missing in the Test results in the bottom right.
Now in the “Replace with:” box, I tell the regex engine what to match it with.
Which in my case are the author initials “JV” followed by a “ - ” seperator followed by a \1
which tells it to put the match that I found earlier back in.
You can see, now that the titles match the crazy way, I want them.
We do an ok, and Tada!
The books are renamed in the library :)
All hail the power of regex!
P.S. Subscribe to my mailing list!
Forward these posts and letters to your friends and get them to subscribe!
P.P.S. Feed my insatiable reading habit.