FormulaCraft

REGEXEXTRACT

REGEXEXTRACT searches a text string for the first match of a regular expression and returns that matched portion. It is a Google Sheets-exclusive function used for advanced text parsing tasks such as extracting phone numbers, dates, codes, or any patterned substring from unstructured text.

Excel
=MID(A2,MIN(FIND({"0","1","2","3","4","5","6","7","8","9"},A2&"0123456789")),LEN(A2))
Google Sheets
=REGEXEXTRACT(A2,"\d+")

Verified example

Computed by a real spreadsheet engine on the sample data below.

TextExtracted Number
Order #1042 shipped1042
Invoice 2055 due2055
Ref 309 pending309
Item 7 in stock7

=MID(A2,MIN(FIND({"0","1","2","3","4","5","6","7","8","9"},A2&"0123456789")),LEN(A2))042 shipped

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

How it works

  1. 1In Google Sheets, identify the text cells you want to parse and write a regular expression pattern for what you want to extract.
  2. 2Enter =REGEXEXTRACT(A2,"\d+") to extract the first sequence of digits from cell A2.
  3. 3Use capturing groups in your pattern to extract a specific sub-portion, e.g., =REGEXEXTRACT(A2,"(\w+)@") to capture the username part of an email.

Need a version for your data?

Try: “Extract the numeric ID from strings like 'Order #1042 shipped'

Related

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: