Learn to grep with BBEdit

Pattern Playground gives you a crash course.


Legendary text and code editor


A powerful tool for searching and replacing text, regular expressions (often referred to as grep) can be intimidating – unless you’ve got BBEdit. The app’s Pattern Playground feature makes this arcane syntax more accessible to developers and writers alike.

Regular-expression syntax lets you quickly find and modify text patterns – for example, replacing all dates in the format dd/mm/yyyy, no matter the numerals. By giving you a live preview of your searches and replacements, BBEdit’s interactive Pattern Playground is one of the easiest ways to learn grep.

Here’s a look at how Pattern Playground lets you experiment with grep on your actual working files – without affecting the original data until you want it to.

Pattern Playground gives you a safe place to learn the daunting (but powerful) world of regular expression.

Pick your pattern

To get started, Choose File > New > Pattern Playground. To practise on a current document, choose it from the “Contents of” pop-up menu; otherwise paste some practice text into the “Contents of” box.

BBEdit offers a slew of example patterns, each with a description explaining what it will match. (For example, you’ll learn that ab|cd will match any occurrence of ab or cd.) Click the templates menu, which looks like a question mark, to choose a pattern to add to the “Search pattern” box. You can also type a pattern manually.

Syntax colouring makes it clear which parts of your pattern will be interpreted as a delimiter (like parentheses and brackets) versus a variable.

As you type, BBEdit shows a live preview of the total matches and highlights the first instance; click Next to cycle through all matches.

Replace in place

Pattern Playground also lets you experiment with replacing text. Enter text in the “Replace pattern” box, and as you cycle through matches, the “Replacement text” field will show you exactly how each change will be applied.

Pattern Playground can also break complex search patterns into subgroups and display the specific text matched by each. You can then use those subgroups as variables in your replacement text.

The same grep syntax works in BBEdit’s Find dialogue.

Put it to use

Now that you’ve perfected your pattern, you can use it on your original document. Click “Use for Find” to copy your settings to BBEdit’s main Find dialogue.

And if you find yourself using the same pattern regularly, you can access it from Pattern Playground’s recent-patterns menu, or save it for quick access. These menus, as well as the templates menu, are also available in the main Find dialogue.


    Legendary text and code editor