Extracting numbers from text strings is a common task in Google Sheets. Whether you're working with data that contains phone numbers, product codes, or numerical values embedded in text, being able to isolate these numbers can be incredibly useful for analysis, calculations, and more. Here, we'll explore five effective ways to extract numbers from text in Google Sheets.
The Importance of Extracting Numbers in Google Sheets
Before diving into the methods, it's essential to understand why extracting numbers is crucial. In many datasets, numbers are mixed with text, making it difficult to perform mathematical operations or analysis. By extracting these numbers, you can unlock the full potential of your data, making it easier to manipulate, calculate, and visualize. This is particularly important in business, finance, and scientific applications where numerical data is king.
Method 1: Using the REGEXEXTRACT Function
Regular Expression Extraction

The REGEXEXTRACT function is a powerful tool for extracting numbers (and text patterns) from strings using regular expressions. Regular expressions (regex) are a sequence of characters that define a search pattern used for matching, locating, and manipulating strings. Here’s how you can use it:
=REGEXEXTRACT(A1,"[0-9]+")
In this formula, A1
is the cell containing the text from which you want to extract numbers, and [0-9]+
is the regular expression pattern that matches one or more digits.
Method 2: Using the REGEXREPLACE Function
Replacing Non-Numeric Characters

While REGEXEXTRACT pulls out the numbers, REGEXREPLACE can be used in a clever way to remove everything except numbers. The idea is to replace all non-numeric characters with an empty string, effectively leaving you with just the numbers.
=REGEXREPLACE(A1,"[^0-9]+","")
In this formula, [^0-9]+
matches one or more characters that are not digits, which are then replaced with nothing (""
), effectively removing them.
Method 3: Using the FILTERXML Function
XML Path Expression

The FILTERXML function is another versatile tool that can be used to extract numbers from text. It works by converting the text into an XML format and then using XPath expressions to find the desired elements.
However, extracting numbers directly using FILTERXML can be complex due to its reliance on XML structure. It's more typically used for parsing data from web pages or XML documents.
Method 4: Using the SPLIT and JOIN Functions
Text Manipulation

For scenarios where the numbers are separated by consistent delimiters, using the SPLIT function to break the text into an array and then JOINing the parts that are numbers can be an effective strategy.
However, this method requires a clear understanding of the text structure and might not be as universally applicable as regex solutions.
Method 5: Using the MID, FIND, and LEN Functions
Text Positioning

In some cases, especially when the numbers are located in a predictable position within the text, using a combination of the MID, FIND, and LEN functions can extract the numbers.
=MID(A1,FIND("numberstarts",A1)+1,LEN(A1))
This method, however, requires a static pattern or position that might not always be present.
Gallery of Google Sheets Functions
Google Sheets Functions for Extracting Numbers










Conclusion
Extracting numbers from text in Google Sheets can be accomplished in several ways, depending on the complexity of the text and the desired outcome. Regular expressions, through functions like REGEXEXTRACT and REGEXREPLACE, offer powerful and flexible solutions. Other methods, involving text manipulation and positioning functions, can also be effective in certain scenarios. Understanding these techniques can significantly enhance your productivity and data analysis capabilities in Google Sheets.
Feel free to ask any questions or share your experiences with extracting numbers in Google Sheets in the comments below.