Excel Regex Functions
Excel Regex Functions
The content in this file was created by Mynda Treacy from My Online Training Hub.
Individual users are permitted to recreate the examples for personal practice only.
Recreating the examples for training or demonstration to others is not permitted, unless writt
The workbook and any sheets within must be accompanied by the following copyright notice:
This sheet must remain in any file that uses this data and or these techniques.
Any uses of this workbook and/or data must include the above attribution.
utorial
raining Hub.
actice only.
permitted, unless written consent is granted by Mynda Treacy.
The REGEXTEST function allows you to determine if a text string matches a specified pattern. This function returns T
the text, and FALSE otherwise.
Pattern: ^[\w.-]+@[\w.-]+\.\w+$
Explanation: The pattern is designed to match a valid email address format with the following structure:
1. Start of the string (^): Ensures the pattern matches from the beginning of the string.
2. Username part ([\w.-]+): Matches one or more characters that are either word characters (letters, digits, u
hyphens.
3. "@" character: Matches the literal "@" symbol separating the username and domain parts.
4. Domain name part ([\w.-]+): Matches one or more characters that are either word characters, dots, or hyp
5. Dot character (\.): Matches the literal dot before the top-level domain.
6. Top-level domain (\w+): Matches one or more word characters, representing the domain suffix.
7. End of the string ($): Ensures the pattern matches up to the end of the string.
last.first@domain #NAME?
watch tutorial
d domain parts.
er word characters, dots, or hyphens.
"^[\w.-]+@[\w.-]+\.\w+$")
REGEXEXTRACT Function read tutorial watch tutorial
The REGEXEXTRACT function extracts substrings that match a specified pattern from the input text.
Example 1: Extract the email address from the text in cell B23.
Pattern: [\w.-]+@[\w.-]+\.\w+
Explanation: The pattern [\w.-]+@[\w.-]+\.\w+ matches an email address format, where:
1. It starts with one or more word characters, dots, or hyphens.
2. Followed by the "@" symbol.
3. Then has one or more word characters, dots, or hyphens.
4. Followed by a dot.
5. Finally ending with one or more word characters.
Contact us at [email protected]
Example 2: Extract the domain name from the URL in cell B36.
Pattern: (?<=//)(?:www\.)?([^/]+)
Explanation:
1. (?<=//): This is a positive lookbehind assertion. It ensures that the match is preceded by // without including // in the
2. (?:www\.)?: Non-capturing group to optionally match "www.".
3. ([^/]+): Capturing group to match the domain name. It matches one or more characters that are not a slash.
https://www.MyOnlineTrainingHub.com/blog
#NAME? {=_xlfn.regexextract(B36, "(?<=//)(?:www\.)?([^/]+)")}
watch tutorial
re_case])
ormat, where:
\w.-]+\.\w+")}
The REGEXREPLACE function replaces substrings matching a pattern with a replacement string.
Example 1: Redact the first 6 digits of the phone number in cell B18.
Pattern: \d{3}-\d{3}
Explanation: The pattern `\d{3}-\d{3}` matches a string of exactly three digits followed by a hyphen and then exactly
1. \d: Matches any digit (0-9). It is a shorthand character class for numeric digits.
2. {3}:
This quantifier specifies that the preceding element (a digit, in this case) must occur exactly t
matches exactly three digits in a row.
3. -: Matches a literal hyphen (dash) character. It is not a special character in this context but is used
itself in the string.
4. \d: Again, matches any digit (0-9).
5. {3}: This quantifier specifies that the preceding element (a digit) must occur exactly three times.
exactly three digits in a row.
Example 2: Replace the first 5 digits of the Social Security Number (SSN) in cell B24 with asterisks.
Pattern: \d{3}-\d{2}
Explanation: The pattern `\d{3}-\d{2}` matches a string of exactly three digits followed by a hyphen and then exactly
My SSN is 123-45-6789
acement string.
ccurrence], [ignore_case])
meric digits.
n this case) must occur exactly three times. So, \d{3}
", "XXX-XXX")
Webinar Replays
Excel Dashboards & Power BI.........................................
Courses
Advanced Excel...............................................................
Advanced Excel Formulas...............................................
Power Query...................................................................
PivotTable Quick Start....................................................
Xtreme PivotTables.........................................................
Power Pivot....................................................................
Excel Dashboards............................................................
Power BI.........................................................................
Excel for Decision Making Under Uncertainty................
Excel for Finance Professionals.......................................
Excel Analysis ToolPak....................................................
Excel for Customer Service Professionals.......................
Excel for Operations Management.................................
Financial Modelling.........................................................
Microsoft Word Masterclass...........................................
Support
Excel Forum....................................................................
https://www.myonlinetraininghub.com/excel-webinars
https://www.myonlinetraininghub.com/excel-expert-upgrade
https://www.myonlinetraininghub.com/advanced-excel-formulas-course
https://www.myonlinetraininghub.com/excel-power-query-course
https://www.myonlinetraininghub.com/excel-pivottable-course-quick-start
https://www.myonlinetraininghub.com/excel-pivottable-course
https://www.myonlinetraininghub.com/power-pivot-course
https://www.myonlinetraininghub.com/excel-dashboard-course
https://www.myonlinetraininghub.com/power-bi-course
https://www.myonlinetraininghub.com/excel-for-decision-making-course
https://www.myonlinetraininghub.com/excel-for-finance-course
https://www.myonlinetraininghub.com/excel-analysis-toolpak-course
https://www.myonlinetraininghub.com/excel-for-customer-service-professionals
https://www.myonlinetraininghub.com/excel-operations-management-course
https://www.myonlinetraininghub.com/financial-modelling-course
https://www.myonlinetraininghub.com/microsoft-word-course
https://www.myonlinetraininghub.com/excel-forum