![](/assets/artwork/1x1-42817eea7ade52607a760cbee00d1495.gif)
![](/assets/artwork/1x1-42817eea7ade52607a760cbee00d1495.gif)
LEVEL UP
Learn Regex With BBEdit
![](/assets/artwork/1x1-42817eea7ade52607a760cbee00d1495.gif)
BBEdit
Legendary text and code editor
A powerful tool for searching and replacing text, regular expressions (often referred to as regex) 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 regular expressions.
Here’s a look at how Pattern Playground lets you experiment with regex on your actual working files—without affecting the original data until you want it to.
![](/assets/artwork/1x1-42817eea7ade52607a760cbee00d1495.gif)
Pick your pattern
To get started, Choose File > New > Pattern Playground. To practice 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.) Above the “Search pattern” box, click the templates menu—it looks like a question mark—to choose a pattern to add; you can also type a pattern manually.
Syntax coloring makes it clear which parts of your pattern will be interpreted as a delimiter (like parentheses and brackets) versus a variable.
As you update or add to your search pattern, 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—or another pattern—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.
![](/assets/artwork/1x1-42817eea7ade52607a760cbee00d1495.gif)
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 dialog.
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 dialog.