REGEXEXTRACT in Google Sheets: A Comprehensive Guide  

Published: August 26, 2024 - 3 min read

Julian Alvarado

Are you struggling to extract specific data from text strings in Google Sheets? The REGEXEXTRACT function can be a powerful tool for this task, but it often intimidates users unfamiliar with regular expressions. This guide will demystify REGEXEXTRACT, walking you through its usage from basic concepts to advanced techniques.

Let’s start with the Basics: REGEXTRACT Syntax and Usage

Let’s look at a simple example to illustrate the basic usage of REGEXEXTRACT:

Suppose you have a cell A1 containing the text “The price is $25.99” and you want to extract the price.

You can use the following formula:

=REGEXEXTRACT(A1, “$d+.d+”)

Screenshot showing a basic use of REGEXEXTRACT in Google Sheets to extract a price from a text string.

This formula will return “25.99”.

Breaking down the regular expression:

  • $ matches the dollar sign (escaped with a backslash because $ has a special meaning in regex)
  • d+ matches one or more digits
  • . matches a literal period
  • d+ matches one or more digits after the decimal point

REGEXEXTRACT Use Cases and Examples

Now that we understand the basics, let’s explore how to use REGEXEXTRACT for various common tasks.

Extracting Numbers from Text

Extracting numbers is a common use case for REGEXEXTRACT. Here are a few examples:

  1. Extracting any number:

    =REGEXEXTRACT(A1, “d+”)
     This will extract the first sequence of one or more digits.
Screenshot of using REGEXEXTRACT in Google Sheets to extract numbers, including integers and decimals, from text.
  1. Extracting a decimal number:
    =REGEXEXTRACT(A1, “d+.d+”)
     This will extract a number with a decimal point.
Screenshot demonstrating how to use REGEXEXTRACT in Google Sheets to extract an email address from a text string.

    Extracting Specific Text Patterns

    REGEXEXTRACT is particularly useful for extracting specific patterns of text:

    1. Extracting an email address:
      =REGEXEXTRACT(A1, “[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Z|a-z]{2,}”)
       This pattern matches most standard email formats.
    Screenshot of a formula in Google Sheets using REGEXEXTRACT to extract a date in MM/DD/YYYY format.
    1. Extracting a URL:
      =REGEXEXTRACT(A1, “https?://S+”)
       This extracts URLs starting with http:// or https://.
    Screenshot showing how to use capture groups with REGEXEXTRACT in Google Sheets to extract multiple pieces of information.
    1. Extracting text between quotation marks:
      =REGEXEXTRACT(A1, “””(.+?)”””)
       This extracts text enclosed in double quotes.
    regexextract-capture-groups-google-sheets

    Working with Dates and Timestamps

    Extracting dates and times can be tricky due to varying formats. Here are some examples:

    1. Extracting a date in MM/DD/YYYY format:
      =REGEXEXTRACT(A1, “d{1,2}/d{1,2}/d{4}”)
    Screenshot of a Google Sheets formula using REGEXEXTRACT with the LEFT function to extract data based on position after pattern matching.
    1. Extracting a time in HH:MM:SS format:

      =REGEXEXTRACT(A1, “d{2}:d{2}:d{2}”)
    Screenshot showing a limitation of REGEXEXTRACT in Google Sheets where only the first match is returned.
    1. Extracting a date and time in ISO 8601 format:

      =REGEXEXTRACT(A1, “d{4}-d{2}-d{2}Td{2}:d{2}:d{2}”)
    Screenshot of an advanced technique in Google Sheets using REGEXEXTRACT to handle complex data extraction scenarios.

    Combining REGEXEXTRACT with Other Functions

    REGEXEXTRACT becomes even more powerful when combined with other Google Sheets functions. Here’s an example using ARRAYFORMULA:

    =ARRAYFORMULA(REGEXEXTRACT(A1:A10, “d+”))

    Coefficient Excel Google Sheets Connectors
    Try the Free Spreadsheet Extension Over 500,000 Pros Are Raving About

    Stop exporting data manually. Sync data from your business systems into Google Sheets or Excel with Coefficient and set it on a refresh schedule.

    Get Started
    Screenshot discussing performance considerations when using REGEXEXTRACT in Google Sheets with large datasets.

    This formula applies the REGEXEXTRACT function to cells A1 through A10, extracting the first number from each cell.

    Advanced REGEXEXTRACT Techniques

    Once you’re comfortable with basic REGEXEXTRACT usage, you can move on to more advanced techniques.

    Using Capture Groups for Multiple Extractions

    Capture groups, denoted by parentheses in regex, allow you to extract multiple pieces of information in one go. For example:

    =REGEXEXTRACT(A1, “(d+) (w+)”)

    If A1 contains “42 apples”, this formula will return “42” in one cell and “apples” in the next.

    Image12

    Take Control with REGEXEXTRACT

    Using REGEXEXTRACT in Google Sheets allows for focused data extraction and manipulation. Begin with straightforward patterns, test them, and gradually advance to more intricate ones. This function becomes increasingly valuable as you become familiar with it.

    Looking for even more from your data analysis? Coefficient offers real-time data connections and advanced analytics in Google Sheets. Start with Coefficient today to make the most of your data.

    Sync Live Data into Your Spreadsheet

    Connect Google Sheets or Excel to your business systems, import your data, and set it on a refresh schedule.

    Try the Spreadsheet Automation Tool Over 500,000 Professionals are Raving About

    Tired of spending endless hours manually pushing and pulling data into Google Sheets? Say goodbye to repetitive tasks and hello to efficiency with Coefficient, the leading spreadsheet automation tool trusted by over 350,000 professionals worldwide.

    Sync data from your CRM, database, ads platforms, and more into Google Sheets in just a few clicks. Set it on a refresh schedule. And, use AI to write formulas and SQL, or build charts and pivots.

    Julian Alvarado Content Marketing
    Julian is a dynamic B2B marketer with 8+ years of experience creating full-funnel marketing journeys, leveraging an analytical background in biological sciences to examine customer needs.
    500,000+ happy users
    Wait, there's more!
    Connect any system to Google Sheets in just seconds.
    Get Started Free

    Trusted By Over 50,000 Companies