Regular expressions might sound intimidating, but Google Sheets makes them surprisingly approachable. With three built-in Google Sheets regex functions — REGEXMATCH, REGEXEXTRACT, and REGEXREPLACE — you can validate data, pull specific text from messy cells, and clean up formatting in seconds. If you've ever struggled with FIND, SUBSTITUTE, or nested LEFT/MID/RIGHT formulas, regex is the upgrade you've been waiting for.
In this guide, I'll walk you through all three functions with real-world examples, a pattern syntax cheat sheet, and copy-paste recipes you can use right away.
Key Takeaways:REGEXMATCH, REGEXEXTRACT, and REGEXREPLACE handle pattern-based text operations in Google SheetsGoogle Sheets uses RE2 syntax — no lookaheads, but covers 95% of common use casesRegex replaces complex nested formulas with a single, readable expressionFor bulk regex find-and-replace across CSV files before import, try SmoothSheet's CSV Find & Replace tool
Regex Basics for Google Sheets
Before diving into functions, you need to understand the building blocks. Google Sheets regex uses RE2 syntax (Google's own regex engine). Here's a quick cheat sheet of the patterns you'll use most:
| Pattern | Meaning | Example | Matches |
|---|---|---|---|
\d | Any digit (0-9) | \d{3} | 123, 456, 789 |
\w | Word character (letter, digit, underscore) | \w+ | hello, user_1 |
. | Any single character | a.c | abc, a1c, a-c |
* | Zero or more of previous | ab*c | ac, abc, abbc |
+ | One or more of previous | \d+ | 1, 42, 9999 |
? | Zero or one of previous | colou?r | color, colour |
[abc] | Any character in set | [aeiou] | a, e, i, o, u |
[^abc] | Any character NOT in set | [^0-9] | Any non-digit |
^ | Start of string | ^Hello | String starting with "Hello" |
$ | End of string | \.com$ | String ending with ".com" |
() | Capture group | (\w+)@ | Captures text before @ |
| | OR operator | cat|dog | cat or dog |
Important: Google Sheets regex is case-sensitive by default. To make a pattern case-insensitive, prefix it with (?i). For example, (?i)hello matches "Hello", "HELLO", and "hello".
REGEXMATCH — Test if Text Matches a Pattern
REGEXMATCH returns TRUE or FALSE based on whether a cell's text matches your pattern. Think of it as a smarter version of SEARCH or FIND — instead of looking for an exact string, you're looking for a pattern.
Syntax
=REGEXMATCH(text, regular_expression)
- text — The cell or string to test
- regular_expression — The pattern to look for (must be a string)
REGEXMATCH checks if the pattern exists anywhere in the text. Use ^ and $ anchors if you need a full-string match.
Example 1: Validate Email Addresses
=REGEXMATCH(A2, "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")This checks whether the value in A2 looks like a valid email address. The pattern matches a username part, an @ symbol, a domain name, and a TLD of at least two characters. It returns TRUE for "[email protected]" and FALSE for "not-an-email".
Example 2: Find Phone Numbers
=REGEXMATCH(A2, "\d{3}[-.]?\d{3}[-.]?\d{4}")Returns TRUE if the cell contains a US-style phone number like 555-123-4567, 555.123.4567, or 5551234567. The [-.]? part makes the separator optional.
Example 3: Check Format Compliance
=REGEXMATCH(A2, "^[A-Z]{2}-\d{4}$")Validates whether a product code follows the format "XX-0000" (two uppercase letters, a hyphen, four digits). Returns TRUE for "AB-1234" and FALSE for "ab-123" or "ABC-12345".
You can use REGEXMATCH inside IF, FILTER, or QUERY to take action based on pattern matches — for example, filtering rows that contain valid email addresses.
REGEXEXTRACT — Pull Out Matching Text
REGEXEXTRACT does exactly what the name suggests: it extracts the first piece of text that matches your pattern. This is where regex truly shines — tasks that would require four or five nested functions become a single formula.
Syntax
=REGEXEXTRACT(text, regular_expression)
- text — The cell or string to extract from
- regular_expression — The pattern to match (use capture groups to control what's returned)
If your pattern contains a capture group (), REGEXEXTRACT returns only the captured portion. Without capture groups, it returns the entire match.
Example 1: Extract Domain from URL
=REGEXEXTRACT(A2, "https?://([^/]+)")Given "https://www.example.com/page", this returns "www.example.com". The capture group ([^/]+) grabs everything after the protocol up to the first slash.
Example 2: Get Numbers from Text
=REGEXEXTRACT(A2, "\d+\.?\d*")Pulls the first number from a text string. From "Total: $1,299.99 USD", it returns "1". If you need to capture the full number including commas, adjust the pattern:
=REGEXEXTRACT(A2, "[\d,]+\.?\d*")Now it returns "1,299.99" from the same string. You can wrap this with VALUE() to convert it to a number for calculations.
Example 3: Multiple Capture Groups
=REGEXEXTRACT(A2, "(\w+)\s(\w+)")When you use multiple capture groups, REGEXEXTRACT returns each group in a separate column. From "John Smith", you get "John" in one cell and "Smith" in the adjacent cell. This is incredibly handy for splitting names, addresses, or any structured text. For more text-splitting techniques, check out the SPLIT function guide.
REGEXREPLACE — Find and Replace with Patterns
REGEXREPLACE is the most powerful of the three. It finds text matching a pattern and replaces it with something else — including references to captured groups. Think of it as SUBSTITUTE on steroids.
Syntax
=REGEXREPLACE(text, regular_expression, replacement)
- text — The cell or string to modify
- regular_expression — The pattern to find
- replacement — What to replace matches with (use
$1,$2for capture group references)
Example 1: Clean Phone Numbers
=REGEXREPLACE(A2, "[^\d]", "")Strips everything except digits from a phone number. Turns "(555) 123-4567" into "5551234567". The pattern [^\d] matches any non-digit character, and the empty string replacement removes them all.
Example 2: Standardize Date Formats
=REGEXREPLACE(A2, "(\d{2})/(\d{2})/(\d{4})", "$3-$1-$2")Converts "01/15/2026" (MM/DD/YYYY) to "2026-01-15" (YYYY-MM-DD). The three capture groups grab month, day, and year, then $3-$1-$2 rearranges them into ISO format.
Example 3: Remove HTML Tags
=REGEXREPLACE(A2, "<[^>]+>", "")Strips all HTML tags from text. Converts "<p>Hello <b>world</b></p>" into "Hello world". The pattern <[^>]+> matches anything between angle brackets.
For combining cleaned text back together after regex operations, the CONCATENATE and TEXTJOIN guide covers all your options.
Practical Recipes
Here are four ready-to-use formulas for common data cleaning tasks. Copy them directly into your spreadsheet.
Extract Email Domain
=REGEXEXTRACT(A2, "@(.+)$")Pulls the domain from an email address. From "[email protected]", it returns "smoothsheet.com". The capture group after @ grabs everything to the end of the string. Pair this with COUNTIF to see which email providers your contacts use most.
Validate Phone Numbers
=REGEXMATCH(A2, "^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$")A comprehensive US phone number validator that accepts formats like +1 (555) 123-4567, 555-123-4567, 555.123.4567, and 5551234567. Returns TRUE for valid formats, FALSE otherwise.
Clean Product SKUs
=UPPER(REGEXREPLACE(A2, "[^A-Za-z0-9-]", ""))Strips special characters from product SKUs and converts to uppercase. Turns "sku: ab-1234/x" into "AB-1234X". This is especially useful when importing product data from CSV files into Google Sheets — inconsistent SKU formats are one of the most common data quality issues. SmoothSheet handles large product catalog imports without browser crashes, so you can focus on cleaning your data with formulas like this rather than fighting upload limits.
Parse URL Parameters
=REGEXEXTRACT(A2, "[?&]utm_source=([^&]+)")Extracts the utm_source parameter from a URL. From "https://example.com/page?utm_source=google&utm_medium=cpc", it returns "google". Change utm_source to any parameter name you need — utm_medium, utm_campaign, ref, etc.
Common Regex Patterns Reference Table
Bookmark this table for the patterns you'll reach for again and again:
| Task | Pattern | Use With |
|---|---|---|
| Any number | \d+ | REGEXEXTRACT |
| Email address | [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} | REGEXMATCH |
| URL | https?://[^\s]+ | REGEXEXTRACT |
| IP address | \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} | REGEXMATCH |
| Only letters | [^a-zA-Z] | REGEXREPLACE (remove non-letters) |
| Only digits | [^\d] | REGEXREPLACE (remove non-digits) |
| Whitespace cleanup | \s+ | REGEXREPLACE (replace with single space) |
| Date (MM/DD/YYYY) | \d{2}/\d{2}/\d{4} | REGEXEXTRACT |
| Zip code (US) | \d{5}(-\d{4})? | REGEXEXTRACT |
| HTML tags | <[^>]+> | REGEXREPLACE (strip tags) |
| Leading/trailing spaces | ^\s+|\s+$ | REGEXREPLACE (trim) |
| Repeated spaces | {2,} | REGEXREPLACE (normalize to single space) |
If you need to run these same patterns across large CSV files before importing them to Sheets, the CSV Find & Replace tool supports full regex and lets you preview changes before applying them — all without leaving your browser.
Frequently Asked Questions
Does Google Sheets regex support lookaheads and lookbehinds?
No. Google Sheets uses the RE2 regex engine, which does not support lookaheads (?=), lookbehinds (?<=), or backreferences (\1) within the pattern itself. However, you can use capture groups with $1, $2 in the replacement string of REGEXREPLACE. For most spreadsheet tasks — validating formats, extracting text, cleaning data — RE2 covers everything you need. See the full RE2 syntax reference for details.
Why does my REGEXMATCH formula return an error?
The most common causes are: (1) your input cell contains a number instead of text — wrap it with TO_TEXT() or TEXT(A2, "0") first, (2) your regex pattern has an unescaped special character like . or ( — escape them with a backslash, or (3) you're using an unsupported RE2 feature like a lookahead. Always test your pattern on a known string first to isolate the issue.
Can I use regex with FILTER or QUERY in Google Sheets?
Yes. REGEXMATCH works perfectly as a condition inside FILTER. For example, =FILTER(A:A, REGEXMATCH(A:A, "pattern")) returns only rows where column A matches your pattern. For the QUERY function, you can use MATCHES in the WHERE clause: =QUERY(A:B, "SELECT * WHERE A MATCHES '.*pattern.*'"). Note that QUERY uses its own regex syntax, which is slightly different from RE2.
How do I make Google Sheets regex case-insensitive?
Prefix your pattern with (?i). For example, =REGEXMATCH(A2, "(?i)hello") matches "Hello", "HELLO", "hello", and any other case variation. This works with all three regex functions — REGEXMATCH, REGEXEXTRACT, and REGEXREPLACE. You can also combine it with other flags, though (?i) is by far the most commonly needed one.
Conclusion
Google Sheets regex functions eliminate the need for complex nested formulas when working with text data. REGEXMATCH validates patterns, REGEXEXTRACT pulls out specific text, and REGEXREPLACE transforms content — all with a single, readable formula. Start with the cheat sheet and practical recipes above, and you'll quickly build confidence writing your own patterns.
When your regex-cleaned data lives in large CSV or Excel files that need to get into Google Sheets, SmoothSheet handles the heavy lifting. It processes imports server-side, so your browser won't freeze on files with hundreds of thousands of rows — giving you more time to focus on the actual data work. Check out the official REGEXMATCH documentation for additional reference, and start putting these patterns to work in your spreadsheets today.