Anyone who does any coding or text editing in Mac OS X is probably familiar with BBEdit. Bare Bones Software, the company behind BBEdit (and it’s now defunct, sibling TextWrangler) wanted to create a simple but very powerful barebones text editing app. BTW I’ve opened 200MB+ text files with BBEdit without a problem. Since its debut on April 1992, BBEdit has been a staple of power Macintosh users everywhere. But one of the least understood features of BBEdit is its GREP advanced find and replace function.
This article will help you get started with BBEdit GREP advanced find and replace functions and point you in the right direction in case you have more advanced questions.
Who Created GREP?
It was created by legendary programmer Ken Thompson in 1974. Thompson also designed the Unix operating system, the UTF-8 character encoding for the world wide web, as well as several operating systems and programming languages.
What Does GREP Mean?
GREP stands for “Global regular expression print”. GREP allows you to quickly run complex find and replace commands that remove or leave characters.
A Simple BBEdit GREP Find & Replace
The “Save as Web Page” feature in Microsoft Word creates a lot of junk code. It’s ridiculous. Word will create 580+ lines of code before it gets to your first paragraph tag. GREP is the perfect tool to clean up Word’s mess.
The wildcard character combination (.*) will replace anything in its spot. Let’s say for example you have an HTML file with multiple font sizes and you want to make them all the same. Something like this:
<span style='font:5.0pt "Times New Roman"'>
<span style='font:6.0pt "Times New Roman"'>
You could run a single GREP that replaces all different font sizes all at once with one size, 7.0pt.
<span style='(.*)pt "Times New Roman"'>
<span style='7.0pt "Times New Roman"'>
Some Great GREP Examples
The useful things that you can do with GREP are endless. Here are a few examples.
Another annoying issue for most programmers is white space. This GREP command will remove all whitespace from the beginning of lines.
Need to search text files for mentions of specific words or phrases? This example searches US President Abraham Lincoln’s famous Gettysburg Address for the words nation, liberty and equality.
Advanced BBEdit GREP
You can find several great BBedit GREP cheatsheets online with advanced search and replace examples.