
Complete Guide to Excel REGEX Functions: Clean Data in 10 Minutes with REGEXEXTRACT, REGEXREPLACE, and REGEXTEST
By using Excel REGEX functions together with Copilot “Clean Data,” even beginners can standardize text data in 10 minutes. Copy and paste the samples in this article to reproduce the same results immediately.
Quick Fix: Clean Email Addresses and Phone Numbers in 10 Minutes
- Run Data → Clean Data to automatically clean up spaces, formatting, and inconsistencies.
- Extract the domain:
=REGEXEXTRACT([@Email],"@(.+)$") - Keep only phone number digits:
=REGEXREPLACE([@Phone],"[^0-9]","") - Format with hyphens:
=REGEXREPLACE(REGEXREPLACE([@Phone],"[^0-9]",""),"^(d{3})(d{3,4})(d{4})$","$1-$2-$3") - Validate the email address:
=REGEXTEST([@Email],"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}$") - For unsupported environments, use Power Query (Split Column, Replace Values, and Trim).
Why Regular Expressions? Principles and Essential Patterns
- Regular expressions find, extract, and replace text using string patterns.
- Email:
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}$ - Domain only:
@(.+)$/ Digits only:[^0-9]/ ZIP code (5 digits):^d{5}$
Practical Examples: Table, Formulas, and Expected Results
| Name | Phone | Address | Note | |
|---|---|---|---|---|
| Kim | kim.s@acme.co.kr | +82 (10) 1234-5678 | Seoul 06236 | VIP |
| Lee | lee99@@example.com | 010.5678.1234 | Busan 49000 | bounce |
| Park | park@shop.io | (010) 4321 0000 | Incheon 22345 | |
| Choi | choi@domain | 82-10-7777-8888 | Gwangju | invalid |
Extract the Domain
=REGEXEXTRACT([@Email],"@(.+)$")
Validate an Email Address
=REGEXTEST([@Email],"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}$")
Keep Only Phone Number Digits → Format with Hyphens
=REGEXREPLACE([@Phone],"[^0-9]","")
=LET(
n, REGEXREPLACE([@Phone],"[^0-9]",""),
IF(REGEXTEST(n,"^d{11}$"), REGEXREPLACE(n,"^(d{3})(d{4})(d{4})$","$1-$2-$3"),
IF(REGEXTEST(n,"^d{10}$"), REGEXREPLACE(n,"^(d{3})(d{3})(d{4})$","$1-$2-$3"),
n)))
Identify ZIP Codes
=REGEXTEST([@Address],"bd{5}b")
LAMBDA Automation
=LAMBDA(text,
LET(n,REGEXREPLACE(text,"[^0-9]",""),
IF(REGEXTEST(n,"^d{11}$"),REGEXREPLACE(n,"^(d{3})(d{4})(d{4})$","$1-$2-$3"),
IF(REGEXTEST(n,"^d{10}$"),REGEXREPLACE(n,"^(d{3})(d{3})(d{4})$","$1-$2-$3"),n))))
Alternatives, Notes, and Checklist
Copilot Clean Data
Use Clean Data for preprocessing first, then finish formatting with REGEX.
Power Query / Text Functions
- You can use Split Column, Replace Values, and Trim as alternatives to REGEX.
- Combine TEXTSPLIT, LEFT/MID/RIGHT, SUBSTITUTE, and SEARCH/FIND.
Troubleshooting
| Symptom | Cause | Solution |
|---|---|---|
| #N/A/blank result | Capture group or pattern mismatch | Check parentheses for capturing and verify anchors. |
| All FALSE | Confusing full and partial matches | Check your use of ^ and $. |
| Incorrect hyphens | Mixed digit lengths | Branch for 10- and 11-digit numbers. |
| REGEX functions unavailable | Unsupported build or channel | Update Excel or use Power Query. |
| Mixed spaces and formatting | Input noise | Use Clean Data first. |
Conclusion
Clean up data in 10 minutes with the combination of Excel REGEX functions and Copilot Clean Data! The next article covers parsing automation with TEXTSPLIT, WRAPROWS, and VSTACK.