0% found this document useful (0 votes)
25 views

Excel Regex Functions

Regex functions

Uploaded by

mspencer1234
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Excel Regex Functions

Regex functions

Uploaded by

mspencer1234
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Copyright Notice read tutorial watch tutorial

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.

owing copyright notice: My Online Training Hub ©.


REGEXTEST Function read tutorial watch tutorial

The REGEXTEST function allows you to determine if a text string matches a specified pattern. This function returns T
the text, and FALSE otherwise.

Syntax: =REGEXTEST(text, pattern, [ignore_case])

- text: The input string to test.

- pattern: The regular expression pattern to match.

- [ignore_case]: Optional. If TRUE (default), the match is case-insensitive.

Example 1: Test if a text string is present:

#NAME? =_xlfn.regextest("Hello World", "world")

Returns TRUE because the function ignores case by default.

Example 2: Validate whether a string is a correctly formatted email address.

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.

[email protected] #NAME? =_xlfn.regextest(B28, "^[\w.-]+@[\w.-]+\.\w+$")


[email protected] #NAME?
[email protected] #NAME?

last.first@domain #NAME?
watch tutorial

d pattern. This function returns TRUE if the pattern is found in

Note: if you don't have a version


of Excel that supports these
functions you'll see @_xlfn.
before the function name.

th the following structure:

ord characters (letters, digits, underscores), dots, or

d domain parts.
er word characters, dots, or hyphens.

ng the domain suffix.

"^[\w.-]+@[\w.-]+\.\w+$")
REGEXEXTRACT Function read tutorial watch tutorial

The REGEXEXTRACT function extracts substrings that match a specified pattern from the input text.

Syntax: =REGEXEXTRACT(text, pattern, [return_mode], [ignore_case])

- text: The input string.

- pattern: The regular expression pattern to extract.

- [return_mode]: Optional. Determines the return format:

- 0: First match (default)

- 1: Multiple matches as an array

- 2: Groupings for the first match as an array

- [ignore_case]: Optional. If TRUE (default), the match is case-insensitive.

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]

#NAME? {=_xlfn.regexextract(B23, "[\w.-]+@[\w.-]+\.\w+")}

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+")}

/ without including // in the result.

hat are not a slash.


www\.)?([^/]+)")}
REGEXREPLACE Function read tutorial

The REGEXREPLACE function replaces substrings matching a pattern with a replacement string.

Syntax: =REGEXREPLACE(text, pattern, replacement, [occurrence], [ignore_cas

- text: The input string.

- pattern: The regular expression pattern to match.

- replacement: The replacement text.

- [occurrence]: Optional. Determines which occurrences are replaced:

- 0: All occurrences (default)

- n: nth occurrence from the start

- -n: nth occurrence from the end

- [ignore_case]: Optional. If TRUE (default), the match is case-insensitive.

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.

My phone number is 123-456-7890

My phone number is XXX-XXX-7890 =_xlfn.regexreplace(B23, "\d{3}-\d{3}", "XXX-XXX")

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

My SSN is *--6789 =_xlfn.regexreplace(B29, "\d{3}-\d{2}","*-")


ad tutorial watch tutorial

acement string.

ccurrence], [ignore_case])

lowed by a hyphen and then exactly three digits.

meric digits.
n this case) must occur exactly three times. So, \d{3}

acter in this context but is used to match the hyphen

must occur exactly three times. So, \d{3} matches

", "XXX-XXX")

B24 with asterisks.


lowed by a hyphen and then exactly two digits.
More Resources
Tutorials
Excel Functions...............................................................
Charting Blog Posts.........................................................
Excel Dashboard Blog Posts............................................

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....................................................................

Follow Us for more Tips & Tutorials


https://www.myonlinetraininghub.com/excel-functions
https://www.myonlinetraininghub.com/category/excel-charts
https://www.myonlinetraininghub.com/category/excel-dashboard

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

You might also like