How to Use the REGEXEXTRACT Function to Pull Specific Data from Text Strings in Google Sheets

Data imported into Google Sheets from external software, CRM systems, or raw web scrapes is rarely formatted cleanly. You often end up with massive text strings where the valuable information—like an email address, a specific ID number, or a zip code—is buried in the middle of messy, unstructured text.

While you can sometimes use functions like LEFT, RIGHT, or MID combined with SEARCH to extract what you need, these formulas quickly become incredibly complex and fragile. The most powerful, professional way to extract exact patterns of data is by using the REGEXEXTRACT function.

What is REGEXEXTRACT?

REGEX stands for “Regular Expressions”. It is a standardized programming language designed entirely for pattern matching within text. Google Sheets supports the RE2 regular expression syntax.

The REGEXEXTRACT function takes a string of text and searches it using a pattern you define. The moment it finds a sequence of characters that matches your pattern, it extracts and isolates that specific data into a new cell.

The Syntax

The formula requires only two arguments:

=REGEXEXTRACT(text, regular_expression)
  • text: The cell containing the messy string you want to search (e.g., A2).
  • regular_expression: The pattern you want to find, wrapped in quotation marks.

Practical Example 1: Extracting an Invoice Number

Imagine cell A2 contains the text: “Payment received for INVOICE-84739 on Tuesday.” You only want to extract the 5-digit invoice number (84739).

You know the number always comes immediately after the word “INVOICE-“, and is always composed of digits.

=REGEXEXTRACT(A2, "INVOICE-([0-9]+)")

How this works:

  • INVOICE- tells the formula to literally look for that exact word.
  • The parentheses () are a “capture group”. This tells Google Sheets: “Find the whole pattern, but only extract what is inside these brackets.”
  • [0-9]+ means “one or more digits from 0 to 9”.

The formula will output: 84739.

Practical Example 2: Extracting a Domain from an Email Address

If cell A2 contains “[email protected]”, and you want to extract just the domain (“marketing.company.com”) to see which companies are signing up for your service.

=REGEXEXTRACT(A2, "@(.+)")

How this works:

  • @ tells the formula to find the @ symbol.
  • () tells it to only extract what comes after the @ symbol.
  • .+ is the regular expression for “literally any character, one or more times.” It will capture everything from the @ symbol to the very end of the string.

The formula will output: marketing.company.com.

Handling Errors with IFERROR

If REGEXEXTRACT cannot find a match for your pattern in the target cell, it will return an ugly #N/A error. When applying this formula down a column of hundreds of rows, these errors can clutter your sheet.

Always wrap your regular expression formulas in an IFERROR function to keep your data clean:

=IFERROR(REGEXEXTRACT(A2, "@(.+)"), "No Match Found")

This will return “No Match Found” (or a blank cell if you use "") instead of an error, making your spreadsheet look much more professional.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.