You've got an email or letter with phone numbers, email addresses, or website links throughout the text—and you'd like to get a list of each of those items on their own. Copy and paste is tedious and time consuming—and, anyway, aren't computers designed to do tasks like that for us?
They are. All you need is a bit of Regex—or regular expression—code and a text editor, and you can pull out the data you want from your text to paste into another app. Or, if you want to automatically extract text from any of several hundreds of apps to send to another app, you can do that too, with Formatter by Zapier. Here's how to use Regex in popular text editors or Formatter in popular web apps.
How to Extract Text with Regex
You're likely familiar with the search tool built into most apps on your computer. Press
F, type in the word you want to find, and the app will highlight every time that word shows up in your text. For example, if you're looking for the number "47" in the sentence "I bought 47 apples," your program's Find tool would highlight the number 47 in that sentence.
What if you instead wanted to find any number in your text? Perhaps your sentence now says "I bought 47 apples and 23 eggs" and you'd like a list of the numbers. Regex—or REGular EXpressions—are what you'll use. Regex lets you tell the computer what type of text you're looking for, using its own syntax. Say we want to find any number. We'd do a regex search for
[0-9]—that will search for anything containing at least one numeral (digits between 0 and 9). Want to find any number or the letter "a"?
[0-9]|a would do the trick, as regex uses the pipe
| character to mean or.
So, if you're looking for email addresses, you could just search for
@ with the normal Find tool to highlight every email address—along with anything that includes an @ symbol, though few things other than email addresses do. A detailed regex script, though, could do better. It could find all the characters around the "@" symbol and select the full email address. And then, with the tools in popular text editor apps, you could copy each email address out of your text.
Want to learn more about Regex? The Regex Wikipedia article does a good job explaining the core syntax, and Regex Tester (pictured above) and RegExr are great ways to learn how to use regex with popovers that explain what scripts do as you write them.
Regex is geeky—but it can actually be easy to use, with regex tools in popular apps along with pre-made regex scripts. First, let's check some quick regex scripts to extract links, emails, and phone numbers, then learn how to use regex in popular text editing programs Sublime Text, Notepad++, and BBEdit:
Regex Scripts to Extract Data
Before you can extract text in your apps, you'll need some regex scripts to use. Here are three scripts we've tested extensively to extract website links, emails, and phone numbers from large blocks of text. Each works with as wide a range of results as possible—and all work in each of the text editors mentioned here. Although they might look like intimidating gobbledygook, all you have to do to use them is copy and paste into the text editor's search commands.
Extract Website Links (via Daring Fireball):
Works with all standard links—including with non-English characters—as long the link includes a leading
www, or a trailing
/ followed by text. For example,
google.com/about would work, as would
Extract Email Addresses (via Almost Perfect Email Regex)
Works with all standard email addresses, sub-domains, and TLDs—as long as the email and domain use standard English characters.
Works with all standard phone numbers, including country and area codes for most international numbers. Anything from
+65 800 123 4567 ext.405 to
865.101.1000 and more should work.
Just use those Regex scripts in your text editor's Find tool, and they should find all the links, emails, and phone numbers in your text. Then use the steps above to copy each of those into their own list.
Want more regex scripts? RegExLib includes a wide range of pre-made regex scripts you can search through—and if you don't find what you need, often Google search results will have the regex scripts you need.
Now, let's learn how to use regex in Sublime Text, Notepad++, BBEdit, and Google Sheets:
How to Use Regex in Sublime Text (Windows, Mac, Linux)
Cross-platform text editor Sublime Text is one of the easiest ways to extract text with regex through its built-in Find all tool.
In the text document that you want to extract specific text from, press
F to open the search bar. Click the
* icon on the far right to enable regex mode, then type or paste in your regex script. Now, click Find All, and Sublime Text will highlight and select every instance of your text it finds.
Want to extract that text and get it in its own list? Just press
F again, then make a new document and paste your results for a list of each of the things you extracted.
Sublime Text Price: Free to evaluate; $70 per user license
How to Regex in Notepad++ (Windows)
Free Windows text editor Notepad++ has a regex option in its Find tool as well—but it doesn't let you copy text the same way Sublime Text does. Instead, we'll use it to put each result on its own line, bookmark those lines, and then copy those bookmarked lines by themselves.
Here's how it works. Just type or paste your text into Notepad++, and press
F to open the search tool. Click the Replace tab, then type or paste your regex script in the Find what: box. Under that, type the following in the Replace with: box to put each result on its own line:
Now, click the Regular expression bullet point in the bottom left corner, then click the Replace All button. That should get every one of your regex search results on their own line.
To copy just your regex results, you'll need to do two more things. First, click the Mark box in the Find window, select Bookmark line in the options, and click Mark All. That will put a red bullet beside each of the lines with your your regex results.
Finally, click the search menu, and select Bookmark -> Copy Bookmarked Lines. Open a new document and paste the text, and you'll have a list of just the text you wanted to find via regex.
Notepad++ Price: Free open-source download
How to Use Regex in BBEdit (Mac)
Perhaps the easiest way to extract text with regex is using the Mac text editor BBEdit. Just enter your text in Regex, press
F to open the Find window, and enter your regex script in the Find box. Check the Grep option in the bottom of the page to run the regex script (which, in BBEdit, is powered by the terminal app
Grep, yet another way you could extract text via regex).
Now, click the Extract button on the right, and BBEdit will make a new text file and add each of your extracted items to the document. It's the quickest way to extract text with regex.
BBEdit Price: Free evaluation; $49.99 license per user
How to Use Regex in Google Sheets (Web)
If you only need one regex result, Google Sheet'
=regextract function lets you use regex inside your spreadsheet to find the first matching result. Just enter
=regextract(, then type in the text you want to search through or select the correct cell, add a comma, then enter your regex script in quotes, and add a closing parenthesis on the end. Google Sheets will then extract the first match from your text—and if your regex script includes sections such as the script pictured which checks for every part of a phone number, Google Sheets will split the result out into one cell per section.
The same thing works in Google Docs, though there's no easy way to copy out all the results. Press
F to open the search dialog, tap the three-dot icon open the full search dialog, add your regex script in the Find dialog, and check the Match using regular expressions box. That will let you find each item that matches your regex query—though you'll have to copy each result manually to extract them from your document.
Google Sheets and Docs Price: Free for personal use; from $5/month G Suite Basic plan for business use
Extract Email Addresses, Phone Numbers, and Links Online
Want something simpler? There are a number of simple web apps that can extract the text you need with a few clicks. The most versatile of the apps we tested is ConvertCSV.com. It can extract email addresses, links, and phone numbers—though it doesn't recognize as many variations as the regex scripts above. And, it can convert your spreadsheet files to different formats if you need, too.
Here are some of the best free simple tools to extract text online:
Extract Phone Numbers: ConvertCSV Phone Number Extractor
Extract Email Addresses, Phone Numbers, and Links Automatically with Zapier
Regex works great when you have a long document with emails and links and numbers, and you need to extract them all. But, far more often, you'll need to extract text from one thing and use it directly in another app.
Learn how to automatically extract data from your apps with Zapier.
Want to use your own custom Regex queries in Zapier? You can do that too with Zapier's Code Steps. Here's how.