TextMate Find & Replace Using Regular Expressions

While working on a new section of the Question-Defense.com web site that will include articles related to Kali Linux I was creating a menu system that would be similar to the Kali Linux menu system. Once the menu was completed with the necessary content and was visually what I was looking for I needed to go back and make some enhancements for SEO (Search Engine Optimization). The goal was to add a HTML title tag where a HTML alt tag already existed and I knew this shouldn’t be to hard to accomplish using regular expressions via TextMate’s find and replace function. Below I describe the issue in more detail along with the regular expression syntax that can be used to accomplish this in the TextMate find and replace window. Please make sure to backup all files you are going to modify before beginning so you can always rollback if need be.

Technology Insights

Use vi To Find And Replace Content While Breaking a Line

The power of the Unix command vi never ceases to amaze me. I have known how to search and replace easily using vi for a long time however I didn’t know how to find and replace plus insert a line break during the replace. After toying around with vi for awhile I was able to figure it out. The example below shows how to find and replace certain text while inserting a line break.

Contents of a File:

sql

  1. (1,2,'title one','2009-04-20 17:55:46','description one'),(2,2,'title two','2009-04-20 18:05:54','description two'),(3,2,'title three','2009-04-20 18:23:10','description three'),(4,2,'title four','2009-04-20 19:33:42','description four'),(5,2,'title five','2009-04-20 19:45:34','description five')