Now Witness the Power of this Fully Armed and Operational Regular Expression

For a recent project, I found myself having to convert 60+ product detail pages from the old table-based format to the new XML-based format. I was doing this on my own, and I didn’t relish the thought of manually editing hundreds of tables of product details. For example, here’s an excerpt from one of the old table-based detail lists:

<table cellspacing="0" cellpadding="0" width="268">
  <tr>
    <td class="specheading" colspan="2">Performance</td>
  </tr>
  <tr>
    <td width="122">Efficiency</td>
    <td width="144">MERV 15</td>
  </tr>
  <tr>
    <td width="122">Warranty</td>
    <td width="144">5-year limited</td>
  </tr>
</table>

Note that it consists of a list of specifications grouped under a title. Now, here’s what the new, XML-based code looked like:

Continue reading

How to Search for This and Not That Using TextWrangler

I’ve been doing a ton of search-and-replace operations at my job lately, and one of the worst ones I did had to do with searching for the word “Comfort.” Unfortunately, this word is absurdly common on this site, and I was getting well over 1000 matches, most of which didn’t apply.

Now, the first thing I tried was making the search case-sensitive. The usage of Comfort I’m searching for is used as part of a product title, so it will always be uppercase. I checked the Case Sensitive checkbox, and that eliminated around 300 results, but I was still getting far too many.

The next thing I noticed is that almost every page on the site included the phrase “Home Comfort” as part of the header. This was matching my search, but wasn’t something I needed. If only there was a way, I thought, to tell it to search for Comfort, but only return it if it is NOT preceded by the word Home.

TextWrangler to the rescue! (Note: you can actually do this with just about any search tool that allows boolian or grep-style searches, but I use TextWrangler, so I’m addressing my post to that). A quick read through the documentation, and I managed to construct the following search:

(?<!Home )Comfort

When I checked the Grep Search checkbox, suddenly my search did exactly what I was looking for, and I now have a much more managable set of about 500 results. Hooray for powerful tools!