How to Extract Digits from Mixed Text in Google Sheets?
Struggling to isolate numbers from a text string? Use REGEXEXTRACT to effortlessly pull out all digits from your data.
Formula Genius can generate a draft from a plain-English prompt. Supported formulas can be checked with sample cases; review the coverage on the result.
The formula
"Extract all digits from a cell that contains mixed text and numbers using REGEXEXTRACT"
=REGEXEXTRACT(A1, "[0-9]+")
This formula extracts the first sequence of digits found in a text string.
Step-by-step breakdown
- Identify the cell containing mixed text and numbers (e.g., A1).
- Use the REGEXEXTRACT function to apply a regular expression.
- The regular expression '[0-9]+' matches one or more digits.
- The function returns the first match of the specified pattern.
Edge cases & warnings
- The cell contains no digits, resulting in an error.
- The cell contains multiple sequences of digits, only the first is returned.
- The cell is empty, leading to an error.
- The digits are formatted with spaces or other characters, which may affect extraction.
Examples
"Order number: 12345ABC"
12345
"Total cost is $99.99"
99
Frequently asked questions
Can REGEXEXTRACT return multiple matches?
No, it only returns the first match found.
What if my text has no digits?
The formula will return an error if no digits are found.
How can I extract all digits, not just the first?
Use ARRAYFORMULA combined with REGEXREPLACE for multiple matches.
Can't find what you need?
Describe a formula in plain English. Formula Genius drafts and explains it, and can check supported formulas on sample cases.