Pulling Out Patterns With REGEXEXTRACT
Extract the part of a string that matches a pattern.
Pulling Out Patterns With REGEXEXTRACT is a free Excel Formulas Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Excel Formulas Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
From Yes/No to Grab the Match
REGEXMATCH tells you whether a pattern is present. Often you want the matched text itself, like the numbers out of Order #4821 or the domain out of an email.
That is the job of REGEXEXTRACT. It finds the first part of the text that matches your pattern and returns that piece as the cell's value.
This is another Google Sheets function. It is one of the cleanest ways to pull structured pieces out of messy imported data.
The REGEXEXTRACT Syntax
REGEXEXTRACT(text, pattern) returns the first substring of text that matches pattern.
If nothing matches, it returns a #N/A error rather than blank, which is important to remember.
The formula below pulls the first run of digits out of A2. For Order 4821 it returns 4821.
=REGEXEXTRACT(A2, "\d+")It Returns Text, Not a Number
REGEXEXTRACT always returns text, even when the matched characters are digits. So 4821 comes back as a text string, not a number you can add up.
To turn it into a real number, wrap it in VALUE. The formula below extracts the digits and converts them so you can do math with the result.
=VALUE(REGEXEXTRACT(A2, "\d+"))Extracting Letters or Codes
Patterns are not limited to digits. To grab a prefix of uppercase letters, use a class with a quantifier.
The formula below pulls the leading letters from a code like INV2024, returning INV. [A-Z]+ means one or more uppercase letters in a row.
=REGEXEXTRACT(A2, "[A-Z]+")Worked Example: Split a Product Code
Suppose A2 holds SKU-4821-RED and you want just the numeric middle. You can describe the position with surrounding context inside the pattern.
The formula below looks for digits that sit between two hyphens and returns 4821. The literal hyphens guide the engine to the right run of digits.
=REGEXEXTRACT(A2, "-(\d+)-")Capture Groups Return Just the Part You Want
Notice the parentheses in the last formula: (\d+). Those are a capture group.
When your pattern contains a capture group, REGEXEXTRACT returns only what is inside the parentheses, not the whole match. That is why -(\d+)- returns 4821 and drops the hyphens.
Capture groups let you match surrounding context for accuracy while still extracting only the slice you care about.
=REGEXEXTRACT(A2, "-(\d+)-")Worked Example: Pull the Email Domain
From sam@coddykit.com you want the domain coddykit.com. Match an @, then capture everything after it up to the end.
The formula below returns the part of A2 that follows the at sign. (.+) captures one or more of any character, and $ ties it to the end of the string.
=REGEXEXTRACT(A2, "@(.+)$")Anchors Make Extraction Precise
Anchors help you grab a piece from a known position. To capture the first word only, anchor to the start and stop at the first space.
The formula below captures the leading non-space characters of A2. For John Smith it returns John. [^ ]+ means one or more characters that are not a space.
=REGEXEXTRACT(A2, "^([^ ]+)")Guarding Against No Match
Because a failed extract throws #N/A, dragging the formula down a column with mixed data can litter your sheet with errors.
Wrap the call in IFERROR to provide a clean fallback. The formula below returns the digits if found, or an empty string if there are none.
=IFERROR(REGEXEXTRACT(A2, "\d+"), "")Extracting With Alternation
The pipe | means or. It lets one pattern match several alternatives. This is great when a code might start with different prefixes.
The formula below extracts whichever status word appears in A2: OPEN, CLOSED, or HOLD. The first one found is returned.
=REGEXEXTRACT(A2, "OPEN|CLOSED|HOLD")Extracting From a Column at Scale
REGEXEXTRACT shines when applied down a whole column of imported data. Each row gets its matching piece pulled into a clean new column you can sort or analyze.
Imagine column A holds order strings like Order 4821 - shipped. The formula below, dragged down column B, extracts just the order number from every row, giving you a tidy numeric-looking column from messy source text.
=REGEXEXTRACT(A2, "Order (\d+)")Quick Check
Check what you know about extracting matches.
Recap: Grab the Matching Piece
You learned that REGEXEXTRACT(text, pattern) returns the first matching substring in Google Sheets. Key takeaways:
- The result is always text; wrap with
VALUEfor numbers - Capture groups in parentheses return only the inner slice
- No match gives
#N/A, so guard withIFERROR |lets one pattern match several alternatives
Next you will go beyond reading and start rewriting text in place with REGEXREPLACE.
Frequently asked questions
Is the “Pulling Out Patterns With REGEXEXTRACT” lesson free?
Yes — the full text of “Pulling Out Patterns With REGEXEXTRACT” is free to read here on the web, and the Excel Formulas Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Excel Formulas Academy course, upgrade to CoddyKit PRO.
What will I learn in “Pulling Out Patterns With REGEXEXTRACT”?
Extract the part of a string that matches a pattern. You practise Excel Formulas Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Excel Formulas Academy?
No prior experience is required. Excel Formulas Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Pulling Out Patterns With REGEXEXTRACT” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Excel Formulas Academy lesson?
Yes. Every Excel Formulas Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Testing Patterns With REGEXMATCH
- Pulling Out Patterns With REGEXEXTRACT
- Replacing Patterns With REGEXREPLACE
- Splitting and Cleaning Messy Data