I was going to write a post about how awesome Regular Expressions are with lots of examples. I spent a lot of last week nailing down the years of data bits that were floating around in my brain. I’d known a bit about how to use them but hadn’t really understood the structure. Well, the structure is awesome and I’m mid-way through comprehending it.
But instead of writing the post, I went and spent over an hour writing 3 in-depth tutorials for another site on how to use Regex for some specific stuff and now all my brain can think is “Regular Expressions — yay!”
If you have any reason at all to go near Regular Expressions, I suggest looking at this helpful quickstart, if nothing else. It outlines some basic syntax and shortcodes with links to more detail on each section. And combing through that site is a good place to start.
What’s Regex good for? It’s handy for doing things in bulk when you’re not doing exactly the same thing each time. For example, a quick find & replace will work if you’re trying to remove “2010/05/31” from all your posts’ links to the url “http://arkhamarchivist.com/2010/05/31/post-title/”.
But if you’ve got 900 posts all of which link back to each other, which were published over a long string of dates, and which used to use dates in their URLs but now just use postnames, then you can either put in every date that happened from start to finish or write an expression for it and get it done in 30 seconds.
You can use Regex to write .htaccess redirects (or redirects in the Redirection plugin) if you change something about your sites link structure.
They’re also helpful if you’re trying to find every time you used multiple forms of the same word or match just about anything. If you’re looking in a small document, you can eyeball it or use multiple searches, but if you’re trying to find something in a database, it’s a huge help.
Regular Expressions — yay!!
(More ideas/tutorials/etc on using Regex to follow at some point. Right now, I’m just sharing the happy.)