Article content and detailed guides remain in English. The selected language applies to controls and quick instructions.

Back to articles

Regular Expressions for Data Cleaning: A Practical Guide for Non-Developers

On this page

What Regular Expressions Are and Why They Matter for Data Cleaning

Regular expressions (regex) are patterns that match text. They let you find, replace and validate data using rules instead of searching for exact text. For data cleaning, regex turns hours of manual work into seconds:

Manual approach Regex approach Time saved
Scroll through 10,000 rows looking for bad emails Pattern match all invalid emails at once Hours to seconds
Find and replace each phone format variation individually One pattern matches all formats 30+ find/replace operations to 1
Manually check each name for extra spaces or punctuation Pattern strips all unwanted characters at once Hours to seconds
Review every URL for consistency Pattern standardises all URLs at once Hours to seconds

Where you can use regex

Tool How to use regex Best for
Google Sheets REGEXMATCH, REGEXEXTRACT, REGEXREPLACE functions Spreadsheet data cleaning
Excel Limited native support; full support with Power Query or VBA Spreadsheet data cleaning
VS Code / Sublime Text Find and Replace with regex enabled Text file cleaning
Notepad++ Find and Replace with regex enabled Text file cleaning (Windows)
Google Docs Find and Replace with regex checkbox Document cleaning
Python (re module) re.findall, re.sub, re.match Programmatic data cleaning
Online regex testers (regex101.com) Test patterns against sample data Learning and testing

Essential Regex Syntax

Building blocks

Symbol Meaning Example Matches
. Any single character a.c "abc", "a1c", "a-c"
* Zero or more of the preceding ab*c "ac", "abc", "abbc"
+ One or more of the preceding ab+c "abc", "abbc" (not "ac")
? Zero or one of the preceding colou?r "color", "colour"
\d Any digit (0-9) \d{3} "123", "456", "789"
\w Any word character (letter, digit, underscore) \w+ "hello", "test_123"
\s Any whitespace (space, tab, newline) \s+ " ", " ", "\t"
[abc] Any character in the set [aeiou] "a", "e", "i", "o", "u"
[^abc] Any character NOT in the set [^0-9] Any non-digit
^ Start of line ^Hello "Hello world" (not "Say Hello")
$ End of line \.com$ "example.com" (at end)
{n} Exactly n occurrences \d{5} "12345"
{n,m} Between n and m occurrences \d{3,5} "123", "1234", "12345"
(...) Capture group (\w+)@(\w+) Captures parts separately
| OR (alternation) cat|dog "cat" or "dog"

Common Data Cleaning Patterns

Email cleaning

Task Find pattern Replace with Before After
Remove spaces around emails \s*(\S+@\S+)\s* $1 " user@example.com " "user@example.com"
Find invalid email format ^[^@]+@[^@]+\.[^@]+$ (negate match) N/A (flag non-matching) "userexample.com" Flagged as invalid
Remove mailto: prefix ^mailto: (empty) "mailto:user@example.com" "user@example.com"
Lowercase emails (use tool-specific lowercase function + regex select) Lowercase all "User@Example.COM" "user@example.com"
Remove duplicate @ signs @{2,} @ "user@@example.com" "user@example.com"
Extract email from text [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} Extract match "Contact: user@example.com for info" "user@example.com"

Phone number cleaning

Task Find pattern Replace with Before After
Extract digits only [^0-9] (empty) "(555) 123-4567" "5551234567"
Format US phone (10 digits) (\d{3})(\d{3})(\d{4}) ($1) $2-$3 "5551234567" "(555) 123-4567"
Remove country code prefix ^\+?1[-.\s]? (empty) "+1-555-123-4567" "555-123-4567"
Find phones with wrong digit count ^\d{1,9}$|^\d{11,}$ N/A (flag) "12345" or "123456789012" Flagged as wrong length

Name cleaning

Task Find pattern Replace with Before After
Remove extra spaces \s{2,} (single space) "John Smith" "John Smith"
Remove leading/trailing spaces ^\s+|\s+$ (empty) " John Smith " "John Smith"
Remove numbers from names [0-9] (empty) "John Smith3" "John Smith"
Find ALL CAPS names ^[A-Z\s]+$ N/A (flag for title case conversion) "JOHN SMITH" Flagged for conversion
Remove titles/prefixes ^(Mr\.?|Mrs\.?|Ms\.?|Dr\.?|Prof\.?)\s* (empty) "Dr. John Smith" "John Smith"
Remove suffixes \s*(Jr\.?|Sr\.?|III|IV|II)\s*$ (empty) "John Smith Jr." "John Smith"

URL cleaning

Task Find pattern Replace with Before After
Remove www prefix ^(https?://)www\. $1 "https://www.example.com" "https://example.com"
Add https if missing ^(?!https?://)(.+) https://$1 "example.com" "https://example.com"
Remove trailing slashes /+$ (empty) "https://example.com/" "https://example.com"
Remove UTM parameters \?utm_[^&]*(&utm_[^&]*)* (empty) "https://example.com?utm_source=google&utm_medium=cpc" "https://example.com"
Extract domain from URL https?://([^/]+) $1 "https://www.example.com/page" "www.example.com"

Address cleaning

Task Find pattern Replace with Before After
Standardise "Street" \b(St\.?|Str\.?)\b Street "123 Main St." "123 Main Street"
Standardise "Avenue" \b(Ave\.?|Av\.?)\b Avenue "456 Park Ave." "456 Park Avenue"
Standardise "Drive" \b(Dr\.?)\b (context: after number) Drive "789 Oak Dr." "789 Oak Drive"
Standardise "Suite" \b(Ste\.?|Ste)\b Suite "Ste. 200" "Suite 200"
Extract ZIP code (US) \b\d{5}(-\d{4})?\b Extract match "New York, NY 10001-1234" "10001-1234"
Extract state abbreviation \b[A-Z]{2}\b(?=\s+\d{5}) Extract match "New York, NY 10001" "NY"

Google Sheets Regex Functions

REGEXMATCH (returns TRUE/FALSE)

Formula What it checks Use case
=REGEXMATCH(A1, "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$") Valid email format Flag invalid emails
=REGEXMATCH(A1, "^\d{10}$") Exactly 10 digits Validate US phone numbers
=REGEXMATCH(A1, "^[A-Z]{2}\d{5}") State + ZIP pattern Validate US address format

REGEXEXTRACT (extracts matching text)

Formula What it extracts Use case
=REGEXEXTRACT(A1, "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}") Email from text Extract email from mixed content
=REGEXEXTRACT(A1, "\d{3}[-.]?\d{3}[-.]?\d{4}") Phone number from text Extract phone from mixed content
=REGEXEXTRACT(A1, "@(.+)$") Domain from email Extract domain for analysis

REGEXREPLACE (find and replace with pattern)

Formula What it does Use case
=REGEXREPLACE(A1, "\s{2,}", " ") Collapse multiple spaces Clean names and addresses
=REGEXREPLACE(A1, "[^0-9]", "") Remove non-digits Clean phone numbers
=REGEXREPLACE(A1, "^\s+|\s+$", "") Trim whitespace Clean all text fields

When to Use Email Extractor Instead of Regex

Regex is powerful for data cleaning, but for email extraction specifically, a dedicated tool is faster and more reliable. Upload your files (spreadsheets, documents, text files, HTML pages, PDFs) to Email Extractor to extract email addresses automatically. The tool handles all 19 supported file formats, applies case-insensitive deduplication and provides downloadable results, without needing to write or debug regex patterns.

Extract emails

Explore tools

Verify emails

Check address validity before using your list.

ZeroBounce

Email Verification

Verifies email lists and provides tools for monitoring deliverability.

Useful when list cleaning and sender health belong in one workflow.

Explore ZeroBounce (opens in a new tab)