I do a lot of work with textual data files, things like membership lists, race results, and team rosters—the sort of thing you get when exporting from a database or saving a spreadsheet in comma-separated value (CSV) format. I want to extract data from these files, clean them up by deleting extraneous bits of data, or reformat them in some way, and the killer app for such text manipulation has long been Bare Bones Software’s BBEdit.
The company has now released BBEdit 13 as a paid upgrade, and despite the app’s 27-year history, Rich Siegel and crew continue to think of new features that keep the powerhouse text editor fresh. This update focuses on the pattern-match searching that has long been BBEdit’s core competency, adding a Pattern Playground for interactively experimenting with regular expressions and a Grep Cheat Sheet that provides quick access to many common regular expressions, complete with brief descriptions. Plus, BBEdit 13 provides live searching in its Find window, automatically highlighting matches as you enter the search term.
A Brief Primer on Regular Expressions
You’re undoubtedly familiar with searching for a string—search this document for “string,” and it would find all instances of the word, along with words that contain those six letters, like “astringent.”
Far more interesting are regular expressions—sequences of characters that define search patterns—which let you do things like find all phone numbers in a document, all phone numbers that have the
607 area code, or even just phone numbers that are formatted as
(###) ###-#### as opposed to
You can use regular expressions when replacing text as well. For instance, putting parentheses around a portion of your search saves that pattern for use in replacement. That enables you to do things like reformat a list of names like
Tim Cook into
Cook, Tim. In essence, you’re finding the first name, saving that to replacement pattern 1, finding the last name, saving that to replacement pattern 2, and then writing a replacement that reverses the order and inserts a comma between the two.
(As an aside, many people use the word “grep” instead of “regular expression” in informal speech. Grep is the name of the command-line utility for performing regular expression searches in Unix. Its name comes from a Unix ed command
g/re/p, which expands to “globally search a regular expression and print.” Since I’m not talking about the Unix utility explicitly, I’ll use “grep” synonymously with “regular expression.”)
Once you start to think in terms of patterns, text-based data become putty in your hands. The hard part is training your brain to look past the specific characters in front of you to the underlying patterns that represent them. That’s where the new features in BBEdit 13 shine. Let’s walk through them with a real-world example where I need to remove the tenths of a second from a file of race finish times (because that’s more precision than is warranted for hand-timing).
Even for someone like me who has been writing regular expressions for years, building a grep search usually requires trial and error. That’s not because I’m lousy at grep, but because it’s easy to assume a source file is more regular than it actually is.
For instance, if I had built a grep search that found a first name and a last name and reformatted them to be Last, First, that search would fail with “Victor Von Doom,” where the last name has two words. Annoyingly, fixing the search to account for two-word last names would mess up differently on “Billie Joe MacAllister,” where the first name has two words. Sometimes real-world data simply doesn’t fit into neat patterns.
The solution has always been to start writing the regular expression in BBEdit’s Find window and then test it continually as you go. It works, but the trial-and-error approach can get tedious. BBEdit’s new Pattern Playground feature simplifies the process for those who are already familiar with regular expressions, and for those who aren’t, it’s a godsend for learning. Here’s how it works.
Open the window from Search > Pattern Playground. It has five sections, some of which you interact with and others which report on the results of your actions:
- Search pattern: Enter your search pattern here. In this case I’m searching for times using the
\dregular expression for “any digit,” enclosing the time without the tenths in parentheses to capture it as replacement pattern 1, and then searching for a period (which has to be prefixed by a backslash because a period means “any character” on its own) and another digit to identify the tenths.
- Capture groups: When you use parentheses to capture patterns for use in replacements, this section of the window shows what each of the replacement patterns will contain.
- Replace pattern: Enter your replacement pattern here. I’ve entered just
\1because I only want the first part of the time I found, without the tenths (replacement pattern 1).
- Replacement text: This field shows what your replacement pattern would end up replacing. Although the field looks editable, all you can do in it is copy.
- Contents of: This large field shows the contents of the file you’re searching, highlighting the found text. The pop-up menu lets you choose a different open file.
Live Search Result Highlighting
Once you finish building a functional search, you can move it to BBEdit’s Find window by clicking Use for Find. Here’s where BBEdit 13’s new live search shows its utility. Whenever the Find window is frontmost, BBEdit highlights all the found terms. Or, more importantly, it doesn’t highlight things that you think should be found but don’t match.
As you can see in this screenshot, BBEdit is highlighting all the 15K times, each of which is over an hour. But many of the 7K times are under an hour, so the search isn’t finding everything I want.
With a quick trip back to the Pattern Playground window. I can fix the search pattern by looking for “zero or more” of the pattern that identifies the hour digit and first colon—
Grep Cheat Sheet
As soon as I realized that I had times both with and without the leading hour digit, I knew how to fix it and didn’t really need to go back to the Pattern Playground window. But what if you don’t know, or you’re working with a regular expression that’s unusual? That’s where the Grep Cheat Sheet comes in handy. Just click the little ? icon that appears anywhere you can perform a grep search to make BBEdit display a menu of common regular expressions. I can’t say that everything you’ll ever need is in there, but it’s a great start.
Other New Features
BBEdit 13 has some other interesting new features as well—see the release notes (which are now always available for the current version by choosing Help > Change Notes) for a full list:
- Apply Text Transform: If you previously built a BBEdit text factory to run a particular transformation across multiple files, BBEdit 13’s new Text > Apply Text Transform command lets you do everything a text factory can do with a single dialog. And if you discover it’s something you might want to use again, click Save As Text Factory.
- Rectangular selections: Previous versions of BBEdit let you make a rectangular selection by holding down the Option key, but that worked only in documents that didn’t have Soft Wrap Text in Edit > Text Options. BBEdit 13 now allows rectangular selection even when that option is on. They can be handy when working with columnar data, and if you’re doing that, don’t miss BBEdit’s Edit > Columns commands.
- Enhanced selection: You’ll notice that the highlighting of search results is purely cosmetic; those items aren’t selected such that you could cut or copy them. However, there is a new selection option that can do that: Search > Find & Select All. Plus, speaking of BBEdit’s column commands, the new Edit > Columns > Select Column command does exactly what you’d think. Also note the new Edit > Select > Highlighted Matches and Edit > Select > Live Search Results commands.
- Strip Trailing Whitespace: It’s common to have one or more spaces at the end of a line, and sometimes that’s problematic. BBEdit 13 now has a Text > Strip Trailing Whitespace command and equivalent text factory operation for removing such cruft.
- Sidebar enhancements: You’ll now find BBEdit > Preferences > Sidebar for tweaking how the sidebar looks and works. Plus, although this option was present in previous versions, note that the List Display Font Size slider in BBEdit > Preferences > Appearance lets you increase the size of the text in the sidebar.
- Dark mode switching: You can now have BBEdit automatically follow the system appearance if you’re set on using Dark mode (see “The Dark Side of Dark Mode,” 31 May 2019). Look in BBEdit > Preferences > Appearance. BBEdit even changes its color scheme to match changes in the system appearance—the release notes explain this approach in detail.
Perhaps the most interesting part of the briefing I had with Bare Bones prior to the release of BBEdit 13 revolved around useful features that shipped in previous versions of BBEdit, but which I had never managed to internalize in my usage. I’ll delve into those some other time, since it was quite embarrassing to discover how much I was missing out on, even as someone who uses BBEdit all the time.
Regardless, BBEdit 13 is a beefy upgrade that adds compelling new capabilities without changing how loyal users have become accustomed to using the app over the years. Particularly if you use grep-based searches, or should be using them but have never figured out grep syntax, BBEdit 13 is well worth the upgrade fee.
System requirements have increased, so BBEdit now requires at least macOS 10.14.2 Mojave (preferably 10.14.6 or later), and it works with 10.15 Catalina.
BBEdit 13 retains the same pricing as BBEdit 12, meaning that a new license costs $49.99. Upgrades from version 12 cost $29.99, or if you own BBEdit 11 or earlier, the upgrade will be $39.99. Mac App Store customers with a subscription immediately gain access to all of BBEdit 13’s new features with no action required.
You can use all of BBEdit’s features for free for 30 days; after that, the core features remain available for free, but you won’t be able to use any menu items marked with a star without paying for a license.