Pulling Out Patterns With REGEXEXTRACT
Extract the part of a string that matches a pattern.
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+")All lessons in this course
- Testing Patterns With REGEXMATCH
- Pulling Out Patterns With REGEXEXTRACT
- Replacing Patterns With REGEXREPLACE
- Splitting and Cleaning Messy Data