{"id":29571,"date":"2023-06-23T22:07:33","date_gmt":"2023-06-23T20:07:33","guid":{"rendered":"https:\/\/www.myexcelonline.com\/?p=29571"},"modified":"2024-05-24T20:31:47","modified_gmt":"2024-05-24T18:31:47","slug":"regex-in-excel","status":"publish","type":"post","link":"https:\/\/www.myexcelonline.com\/meo-staging\/blog\/regex-in-excel\/","title":{"rendered":"Simplify Data Analysis with Regex in Excel &#8211; #1 Cheat Sheet for Excel Users"},"content":{"rendered":"<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/B2B83A38-023B-4765-9FBB-042ED083064B.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-29671\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/B2B83A38-023B-4765-9FBB-042ED083064B-1024x576.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"1024\" height=\"576\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/B2B83A38-023B-4765-9FBB-042ED083064B-1024x576.png 1024w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/B2B83A38-023B-4765-9FBB-042ED083064B-300x169.png 300w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/B2B83A38-023B-4765-9FBB-042ED083064B-768x432.png 768w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/B2B83A38-023B-4765-9FBB-042ED083064B.png 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>Regex in Excel is a very powerful tool <a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/blog\/large-if-formulas\/\" target=\"_blank\" rel=\"noopener\">in data analysis<\/a> that is used to <strong>simplify and streamline various tasks<\/strong>. You can use regex to<strong> extract,\u00a0replace or match substrings<\/strong> based on user-defined patterns.<\/p>\n<p>While many of us have relied on <strong>text functions like FIND, LEFT, and SUBSTITUTE<\/strong> in Excel to perform operations on text strings. It is important to understand that these functions <strong>come with their limitations<\/strong>. You can use <a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/free-excel-macros-and-vba-training-2021\/\" target=\"_blank\"><strong>Visual Basic for Applications (VBA)<\/strong><\/a> in Excel to surpass this limitation. It can provides<strong> enhanced flexibility and time-saving benefits<\/strong>.<\/p>\n<p>In this article, we will be exploring the following topics in detail &#8211;<\/p>\n<p>Let&#8217;s dive into the article to understand and unlock the potential of <a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/blog\/remove-whitespace-in-regex\/\" target=\"_blank\" rel=\"noopener\">Regex in Excel<\/a>!<\/p>\n<div class=\"om-placeholder\">\n<h4><strong>Download the Excel Workbook below to follow along and understand how to use Regex in Excel \u2013<br \/>\n<\/strong><a class=\"IRPP_minimalist icon-download\" href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/RegEx-Function-in-Excel.xlsm\" target=\"_blank\"><span class=\"ctaText px-3 text-capitalize\"><strong>download excel workbook<\/strong><\/span><span class=\"postTitle px-3\">RegEx-Function-in-Excel.xlsm<\/span><\/a><\/h4>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong><span id=\"1\" style=\"color: #ff0000\">Regex in Excel<\/span><\/strong><\/p>\n<p>Regex is a<strong> sequence of characters<\/strong> consisting of letters, numbers, special characters, operators, and constructs. It is a powerful tool that enables users to <strong>describe and identify patterns<\/strong> within a text. You can <strong>define rules using regex to extract, replace, or match patterns<\/strong> based on certain criteria.<\/p>\n<p>For example, [from\u2013to] means you can match any character mentioned in the bracket.<\/p>\n<ul>\n<li><strong>[0-9]<\/strong> &#8211; Any single digit from 0 to 9<\/li>\n<li><strong>[a-z]<\/strong> &#8211; Any single lowercase letter<\/li>\n<li><strong>[A-Z]<\/strong> &#8211; Any single uppercase letter<\/li>\n<\/ul>\n<p>Although <strong>Excel lacks a built-in regex function<\/strong>, you can use regex with the help of <strong>Visual Basic for Applications (<a class=\"wpil_keyword_link\" title=\"VBA\" href=\"https:\/\/www.myexcelonline.com\/meo-staging\/blog\/101-excel-macros-examples\/\" target=\"_blank\" rel=\"noopener\" data-wpil-keyword-link=\"linked\">VBA<\/a>)<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n<p><strong><span id=\"2\" style=\"color: #ff0000\">How to Use VBA for Regex<\/span><\/strong><\/p>\n<p>You can use VBA to create custom <a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/blog\/regex-functions\/\" target=\"_blank\" rel=\"noopener\">Regex Functions in Excel<\/a>. Let\u2019s see how it can be done:<\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 1: <\/span><\/strong>Press<strong>\u00a0Alt + F11<\/strong>\u00a0to open the window for\u00a0<strong>Microsoft Visual Basic for Applications<\/strong>.<\/p>\n<p>Or, Go to\u00a0<strong>Developer<\/strong>\u00a0&gt;\u00a0<strong>Visual Basic<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2017\/10\/Screenshot-311.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-23108\" title=\"Show &amp; Hide Field List in Excel Pivot Table\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2017\/10\/Screenshot-311.png\" alt=\"Show &amp; Hide Field List in Excel Pivot Table\" width=\"1018\" height=\"127\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2017\/10\/Screenshot-311.png 1018w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2017\/10\/Screenshot-311-300x37.png 300w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2017\/10\/Screenshot-311-768x96.png 768w\" sizes=\"(max-width: 1018px) 100vw, 1018px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 2: <\/span><\/strong>Go to <strong>Insert<\/strong>\u00a0&gt;\u00a0<strong>Module<\/strong>\u00a0and copy-paste the following code in it.<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2021\/03\/Screenshot-349.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-23245\" title=\"Show &amp; Hide Field List in Excel Pivot Table\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2021\/03\/Screenshot-349.png\" alt=\"Show &amp; Hide Field List in Excel Pivot Table\" width=\"555\" height=\"187\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2021\/03\/Screenshot-349.png 555w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2021\/03\/Screenshot-349-300x101.png 300w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 3: <\/span> <a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/VBA-Code-for-Regex-in-Excel.txt\" target=\"_blank\">Download<\/a><\/strong> this file and copy-paste the code into the module section &#8211;<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-in-Excel-2-1.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29586\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-in-Excel-2-1.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"1178\" height=\"352\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-in-Excel-2-1.png 1178w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-in-Excel-2-1-300x90.png 300w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-in-Excel-2-1-1024x306.png 1024w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-in-Excel-2-1-768x229.png 768w\" sizes=\"(max-width: 1178px) 100vw, 1178px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 4: <\/span><\/strong>Press <strong>Ctrl + S<\/strong>\u00a0to save the Excel Workbook.<\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 5: <\/span><\/strong>In the dialog box, select <strong>No<\/strong>\u00a0to save the WorkBook as Macro enabled.<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2021\/03\/Screenshot-351.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-23247\" title=\"Show &amp; Hide Field List in Excel Pivot Table\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2021\/03\/Screenshot-351.png\" alt=\"Show &amp; Hide Field List in Excel Pivot Table\" width=\"652\" height=\"221\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2021\/03\/Screenshot-351.png 652w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2021\/03\/Screenshot-351-300x102.png 300w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 6: <\/span><\/strong>In the Save as dialog box, select <strong>Excel Macro-Enabled Workbook<\/strong>\u00a0from Save as type dropdown. Click Save.<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-in-Excel-1.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29581\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-in-Excel-1.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"938\" height=\"621\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-in-Excel-1.png 938w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-in-Excel-1-300x199.png 300w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-in-Excel-1-768x508.png 768w\" sizes=\"(max-width: 938px) 100vw, 938px\" \/><\/a><\/p>\n<p>This Macro-Enabled Workbook will now have three custom Regex Functions saved and ready to be used. Let&#8217;s take a look at them.<\/p>\n<p>&nbsp;<\/p>\n<p><strong><span id=\"3\" style=\"color: #ff0000\">Match Patterns using Regex<\/span><\/strong><\/p>\n<p>The custom function that has been created using VBA to match patterns is used <strong>MatchPatternUsingRegex<\/strong>. The syntax of this function is &#8211;<\/p>\n<p><em>=MatchPatternUsingRegex(input_range, pattern, [match_case])<\/em><\/p>\n<p>where,<\/p>\n<ul>\n<li><strong>input_range<\/strong> &#8211; the range of cells you want to search for the pattern. Required.<\/li>\n<li><strong>pattern<\/strong> &#8211; the regular expression pattern you want to match. Required.<\/li>\n<li><strong>match_case<\/strong> &#8211; specify whether the pattern should be case-sensitive or not (default is True). Optional.<\/li>\n<\/ul>\n<p>In this example, we want to check if the email address mentioned in column A belongs to the domain &#8220;@gmail.com&#8221;.<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-3.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-29588\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-3.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"214\" height=\"474\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-3.png 304w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-3-136x300.png 136w\" sizes=\"(max-width: 214px) 100vw, 214px\" \/><\/a><\/p>\n<p>The pattern that we will be using to check the same is &#8211;<\/p>\n<p><strong>[a-zA-Z0-9._%+-]+@gmail\\.com<\/strong><\/p>\n<ul>\n<li><strong>[a-zA-Z0-9._%+-]+<\/strong> This part matches one or more occurrences of any of these lowercase letters (a-z), uppercase letters (A-Z), digits (0-9), period (.), underscore (_), percent sign (%), plus sign (+), or hyphen\/minus sign (-). The pattern will match these characters before the @ sign.<\/li>\n<li><strong>gmail\\.com<\/strong> This part will match the exact text string &#8220;@gmail.com&#8221;.<\/li>\n<\/ul>\n<p>Follow the steps below to match patterns using Regex in Excel &#8211;<\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 1: <\/span><\/strong>Enter the <strong>formula<\/strong>.<\/p>\n<p><strong>=MatchPatternUsingRegex(<\/strong><\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-4.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29589\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-4.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"750\" height=\"669\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-4.png 750w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-4-300x268.png 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 2: <\/span><\/strong>Select the cell containing the <strong>text you want to check<\/strong>.<\/p>\n<p><strong>=MatchPatternUsingRegex(A2,<\/strong><\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-5.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29590\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-5.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"740\" height=\"607\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-5.png 740w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-5-300x246.png 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 3: <\/span><\/strong>Type the <strong>pattern you want to check.<\/strong><\/p>\n<p><strong>=MatchPatternUsingRegex(A2,&#8221;[a-zA-Z0-9._%+-]+@gmail\\.com&#8221;)<\/strong><\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-6.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29591\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-6.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"820\" height=\"597\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-6.png 820w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-6-300x218.png 300w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-6-768x559.png 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><\/p>\n<p>In the result, you can see that all the email addresses that belong to Gmail provide the value TRUE, else FALSE.<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-7.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29592\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-7.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"769\" height=\"598\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-7.png 769w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Regex-7-300x233.png 300w\" sizes=\"(max-width: 769px) 100vw, 769px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span id=\"4\" style=\"color: #ff0000\">Replace Patterns using Regex<\/span><\/strong><\/p>\n<p>The custom function that has been created using VBA to replace patterns is used <strong>ReplaceUsingRegex<\/strong>. The syntax of this function is &#8211;<\/p>\n<p>=ReplaceUsingRegex(text, pattern, replacement)<\/p>\n<p>where,<\/p>\n<ul>\n<li><strong>text<\/strong> &#8211; the cells that contain the text string. Required.<\/li>\n<li><strong>pattern<\/strong> &#8211; the regular expression pattern you want to replace. Required.<\/li>\n<li><strong>replacement<\/strong> &#8211; the text that you want to replace the pattern with. Required.<\/li>\n<\/ul>\n<p>In this example, we have a list of names but it contains unwanted characters like exclamation mark (!), @, full stop (.), digits (0-9), etc. We will use this function to replace all unwanted characters with an empty string.<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-407.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29593\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-407.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"209\" height=\"625\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-407.png 209w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-407-100x300.png 100w\" sizes=\"(max-width: 209px) 100vw, 209px\" \/><\/a><\/p>\n<p>The pattern that we will be using is &#8220;[^a-zA-Z\/s]&#8221;. It means any character that is not mentioned in the bracket i.e. lowercase letters (a-z), uppercase letters (A-Z), and space (\/s).<\/p>\n<p>Follow the steps below to replace patterns using Regex in Excel &#8211;<\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 1: <\/span><\/strong>Enter the <strong>formula<\/strong>.<\/p>\n<p><strong>=ReplaceUsingRegex(<\/strong><\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-408.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29594\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-408.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"721\" height=\"603\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-408.png 721w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-408-300x251.png 300w\" sizes=\"(max-width: 721px) 100vw, 721px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 2: <\/span><\/strong>Select the cell containing the <strong>text string<\/strong>.<\/p>\n<p><strong>=ReplaceUsingRegex(A2,<\/strong><\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-409.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29595\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-409.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"715\" height=\"613\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-409.png 715w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-409-300x257.png 300w\" sizes=\"(max-width: 715px) 100vw, 715px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 3: <\/span><\/strong>Type the <strong>pattern you want to replace.<\/strong><\/p>\n<p><strong>=ReplaceUsingRegex(A2,&#8221;[^a-zA-Z\/s]&#8221;<\/strong><\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-417.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29603\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-417.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"727\" height=\"597\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-417.png 727w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-417-300x246.png 300w\" sizes=\"(max-width: 727px) 100vw, 727px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 4: <\/span><\/strong>Type an<strong> empty string<\/strong>.<\/p>\n<p><strong>=ReplaceUsingRegex(A2,&#8221;[^a-zA-Z\/s]&#8221;,&#8221;&#8221;)<\/strong><\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-419.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29604\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-419.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"723\" height=\"594\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-419.png 723w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-419-300x246.png 300w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/a><\/p>\n<p>In the result, you can see that all the characters except lowercase letters (a-z), uppercase letters (A-Z), and space (\/s) have been replaced by an empty string.<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-418.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29605\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-418.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"725\" height=\"599\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-418.png 725w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-418-300x248.png 300w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span id=\"5\" style=\"color: #ff0000\">Extract Patterns using Regex<\/span><\/strong><\/p>\n<p>The custom function that has been created using VBA to extract patterns from text strings is <strong>ExtractUsingRegex<\/strong>. The syntax of this function is &#8211;<\/p>\n<p>=ExtractUsingRegex(text, pattern)<\/p>\n<p>where,<\/p>\n<ul>\n<li><strong>text<\/strong> &#8211; the cells that contain the text string. Required.<\/li>\n<li><b>pattern<\/b>&#8211; regular expression pattern you want to extract. Required.<\/li>\n<\/ul>\n<p>In this example, we have a list of names and want to extract the last name. Here, we will be using the pattern <strong>&#8220;\\w+$&#8221;<\/strong> that will help us extract the <strong>end of the string<\/strong>.<\/p>\n<ul>\n<li><strong>\/w<\/strong> &#8211; indicates any character including uppercase letters, lowercase letters, digits, and underscore.<\/li>\n<li><strong>+<\/strong> &#8211; indicates one or more characters<\/li>\n<li><strong>$<\/strong> &#8211; indicates the end of the string.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-412.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29598\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-412.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"213\" height=\"559\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-412.png 213w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-412-114x300.png 114w\" sizes=\"(max-width: 213px) 100vw, 213px\" \/><\/a><\/p>\n<p>Follow the steps below to extract patterns using Regex in Excel &#8211;<\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 1: <\/span><\/strong>Enter the <strong>formula<\/strong>.<\/p>\n<p><strong>=ExtractUsingRegex(<\/strong><\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-413.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29599\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-413.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"724\" height=\"603\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-413.png 724w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-413-300x250.png 300w\" sizes=\"(max-width: 724px) 100vw, 724px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 2: <\/span><\/strong>Select the cell containing the <strong>text string<\/strong>.<\/p>\n<p><strong>=ExtractUsingRegex(A2,<\/strong><\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-414.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29600\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-414.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"729\" height=\"601\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-414.png 729w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-414-300x247.png 300w\" sizes=\"(max-width: 729px) 100vw, 729px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff0000\">STEP 3: <\/span><\/strong>Type the <strong>pattern you want to extract.<\/strong><\/p>\n<p><strong>=ExtractUsingRegex(A2,&#8221;\\w+$&#8221;)<\/strong><\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-415.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29601\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-415.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"718\" height=\"598\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-415.png 718w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-415-300x250.png 300w\" sizes=\"(max-width: 718px) 100vw, 718px\" \/><\/a><\/p>\n<p>In the result, we can see that the end of the string i.e. the last name has been extracted.<\/p>\n<p><a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-416.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-29602\" title=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" src=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-416.png\" alt=\"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users\" width=\"722\" height=\"599\" srcset=\"https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-416.png 722w, https:\/\/www.myexcelonline.com\/meo-staging\/wp-content\/uploads\/2023\/06\/Screenshot-416-300x249.png 300w\" sizes=\"(max-width: 722px) 100vw, 722px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Regex is an extremely<strong> powerful tool<\/strong> that can be] used to make<strong> data analysis tasks simpler and streamlined<\/strong>. While Excel provides<strong> built-in text functions, they have limitations<\/strong>.<\/p>\n<p><strong>VBA<\/strong> in Excel is a <strong>flexible and time-saving alternative<\/strong> for Excel users. VBA for regex can be<strong> used for matching patterns, replacing patterns, and extracting patterns<\/strong>. By using <strong>custom regex functions<\/strong> created through VBA, users can <strong>apply complex pattern matching and manipulation<\/strong> to text <a href=\"https:\/\/www.myexcelonline.com\/meo-staging\/blog\/structured-references\/\" target=\"_blank\" rel=\"noopener\">data in Excel<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Regex in Excel is a very powerful tool in data analysis that is used to simplify and streamline various tasks. You can use regex to extract,\u00a0replace or match substrings based on user-defined patterns. While many of us have relied on text functions like FIND, LEFT, and SUBSTITUTE in Excel to perform operations on text strings. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":29671,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"cos_headline_score":0,"cos_seo_score":0,"cos_headline_text":"Simplify Data Analysis with Regex in Excel - #1 Cheat Sheet for Excel Users","cos_headline_has_been_analyzed":false,"cos_last_analyzed_headline":[],"om_disable_all_campaigns":false},"categories":[6,14],"tags":[1263,1262,1261],"acf":[],"_links":{"self":[{"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/posts\/29571"}],"collection":[{"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/comments?post=29571"}],"version-history":[{"count":0,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/posts\/29571\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/media\/29671"}],"wp:attachment":[{"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/media?parent=29571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/categories?post=29571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.myexcelonline.com\/meo-staging\/wp-json\/wp\/v2\/tags?post=29571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}