This site is rarely updated. benbrophy.com is more up-to-date. - Ben

Regular Expression of Joy

Whenever I use regular expressions to fix up a whole bunch of pages at once, I feel a burst of nerd euphoria.

The informational pages at the top level of the Stellar website are templated using SSI. For reasons of expediency, we never put in separate pages for each page, even though it's quite doable using SSI variables.

I wanted each page title to match the heading at the top of the text (these are consistently header 2 tags). I had to preserve what ever header material was there already, but stick a comment with the SSI variable info on the top of the page. So after some R&D here's what i came up with:

Search for: \A((.|\s)*?)<h2>(.*?)</h2>

Replace with:<!--#set var="PAGETITLE" value="Stellar: \3"-->\r\1\r\<h2>\3</h2>

Voila. BBedit was churning through pages doing the work of 20 web designers at once.

Comments | 2005-03-08