Wolf’s Little Store

December 13, 2007

Cleaning up HTML

Kicking out inline styles with regular expressions

So… you have to clean up some code. Let’s say your client copied their old website content to his new content management system. Your content management system. And what he copied looks like this:

codemess.gif

Fire up the “find and replace” function of your editor and check the box “Regular expression”. Then in the find field, enter style=".+". Leave the replace field empty. You’re replacing whatever is found with nothing - it’s not very logical, but this is how computers work. So we have to deal with that.

Now press the “replace all” button and your code is pretty clean again.

Extra clean with HTML Tidy

HTML Tidy is pretty helpful when cleaning up code: check it out at http://tidy.sourceforge.net/. Or just select the text you want to run through Tidy and hit CTRL+SHIFT+H in Textmate.

6 responses

Leave a Reply

Write in English, stay on-topic and polite.