{"id":9775,"date":"2020-06-24T17:11:09","date_gmt":"2020-06-24T11:41:09","guid":{"rendered":"http:\/\/ivyproschool.com\/blog\/?p=9775"},"modified":"2021-06-10T16:29:49","modified_gmt":"2021-06-10T10:59:49","slug":"step-by-step-guide-to-python-regular-expressions","status":"publish","type":"post","link":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/","title":{"rendered":"Step by Step Guide of Python Regular Expressions &#8211; Part 1"},"content":{"rendered":"<p><a href=\"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\" wp-image-9795 aligncenter\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-1-300x139.png\" alt=\"Cover image\" width=\"650\" height=\"301\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-1-300x139.png 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-1-768x356.png 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-1-1024x474.png 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-1.png 1080w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/a><\/p>\n<p><a href=\" \"><br \/>\n<\/a><a href=\" \">The very first article in the NLP series introduced <\/a><a href=\"https:\/\/ivyproschool.com\/blog\/2020\/06\/10\/introduction-to-natural-language-processing\/\">Natural Language Processing<\/a>. We then explained <a href=\"https:\/\/ivyproschool.com\/blog\/2020\/06\/17\/string-operations-using-python-for-nlp-beginners\/\">String Operations<\/a> that can be performed on text using Python. Further, in the quest to strengthen our text pre-processing, we must have a good understanding of Regular Expressions. This article is the first part of a step by step guide of Python Regular expressions.<\/p>\n<h2>What is Regular Expression?<\/h2>\n<p>Regular Expressions, also called <em>Reg Exs<\/em>, are a special sequence of characters often denoted using the raw string notation. Reg Ex helps create string patterns and use them for searching and substituting specific pattern matches in textual data. Many other programming languages like Java, Perl, Unix also support regular expression functionality.<\/p>\n<h2>Why do we need Regular expression?<\/h2>\n<p>It is pertinent if you are wondering what is the need for regular expressions. In our previous article, we explained several basic string operations like split, join, strip, etc. Should not these suffice? Let us look at the below scenarios before answering this question.<\/p>\n<p>Consider a sample text &#8211; &#8220;N123tur123l l123ngu123ge Processing&#8221;. We want to replace the string &#8216;123&#8217; with &#8216;a&#8217;. A simple string operation code to achieve the task looks like this.<\/p>\n<div>\n<pre>string_sample = \"N123tur123l l123ngu123ge Processing\"\r\nstring_sample.replace(\"123\",\"a\")<\/pre>\n<\/div>\n<div>Replaced. Done. Great. Now consider another scenario.<\/div>\n<div><\/div>\n<div>The sample text is &#8220;N123tur345l l789ngu567ge Processing&#8221; where we want to replace numbers with &#8216;a&#8217; just like the last example. Will the task be possible with a single application of replace method on the string variable? As a solution, one will want to fulfill this task by successively applying the replace method on the string variable. Surely not a good coding practice. What if there is a large volume of text requiring the numeric to alphabetic replacement of some sort? This is where we will need Regular Expression.<\/div>\n<h2>Python Regular Expression Package:<\/h2>\n<p>The <a href=\"https:\/\/docs.python.org\/3\/library\/re.html\">re package<\/a> in Python provides us with a lot of options to perform text pre-processing. The regularly used methods are <strong>compiled, search, match, split, sub, subn, escape, findall, finditer<\/strong>. There is an optional flag that can be provided as an argument in these methods. For example, <strong>re.IGNORECASE, re.ASCII, re.Unicode, re.DOTALL, re.MULTILINE<\/strong>, etc. To specify regular expressions, <strong>metacharacters<\/strong> are used. We can also utilize <strong>special sequences <\/strong>and<strong> sets<\/strong> that make commonly used patterns easy to write.<\/p>\n<p>Metacharacters &#8211; These are characters with a special meaning. For example &nbsp;<strong>.<\/strong> <strong>^<\/strong> <strong>$<\/strong> <strong>*<\/strong> <strong>+<\/strong> <strong>?<\/strong> <strong>{}<\/strong> <strong>()<\/strong> <strong>\\<\/strong> <strong>|<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-9791 aligncenter\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/cc7c2190-6b8e-451a-95cc-23b10e0210b2-300x147.jpg\" alt=\"Metacharacters - step by step guide of Python Regular Ex[ressions\" width=\"750\" height=\"368\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/cc7c2190-6b8e-451a-95cc-23b10e0210b2-300x147.jpg 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/cc7c2190-6b8e-451a-95cc-23b10e0210b2-1024x501.jpg 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/cc7c2190-6b8e-451a-95cc-23b10e0210b2.jpg 1080w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>Special Sequence &#8211; A special sequence is a <code class=\"w3-codespan\">\\<\/code> followed by one of the characters and has a special meaning. For example <strong>\\w, \\W, \\d, \\D<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-9792 aligncenter\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/8c83c588-18f5-4df5-8339-a9814f2b2662-300x180.jpg\" alt=\"Special Sequence of Regular Expressions\" width=\"749\" height=\"449\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/8c83c588-18f5-4df5-8339-a9814f2b2662-300x180.jpg 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/8c83c588-18f5-4df5-8339-a9814f2b2662-768x461.jpg 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/8c83c588-18f5-4df5-8339-a9814f2b2662-1024x614.jpg 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/8c83c588-18f5-4df5-8339-a9814f2b2662.jpg 1080w\" sizes=\"auto, (max-width: 749px) 100vw, 749px\" \/><\/p>\n<p>Sets &#8211; It is a set of characters inside a pair of square brackets <code class=\"w3-codespan\">[]<\/code>with a special meaning. For example <strong>[a-zA-Z], [0-9]<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-9793 aligncenter\" src=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/78baed9a-daec-45b4-9a4b-ec75f4cf546e-300x133.jpg\" alt=\"Sets of Regular Expression\" width=\"810\" height=\"359\" srcset=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/78baed9a-daec-45b4-9a4b-ec75f4cf546e-300x133.jpg 300w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/78baed9a-daec-45b4-9a4b-ec75f4cf546e-768x341.jpg 768w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/78baed9a-daec-45b4-9a4b-ec75f4cf546e-1024x455.jpg 1024w, https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/78baed9a-daec-45b4-9a4b-ec75f4cf546e.jpg 1080w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/p>\n<p>We are going to provide some practical scenarios, apply various regex commands, and explain various results.<\/p>\n<h2>Example Scenarios to apply Regular Expressions:<\/h2>\n<p>I am considering two scenarios related to applying Natural Language Processing. The first is the Sentiment Analysis of COVID19 Tweets. Another scenario is Topic Modelling on movie reviews posted on IMDB. One needs to perform some text cleaning before applying NLP techniques to identify sentiment or for Topic Modelling. Let us now define two string variables that will be used throughout for applying the regular expression commands.<\/p>\n<div>\n<div>\n<pre>movie_review = \"\"\"Troy is loosely based on Homer's 'Iliad', Wolfgang Petersen directs this epic war film, with an ensemble cast\r\nincluding Brad Pitt, Eric Bana, Orlando Bloom, Diane Kruger, Troy Sean Bean, Brian Cox, Rose Byrne, Garrett Hedlund,&nbsp;\r\nPeter O' Toole, Brendan Gleeson, &amp; Tyler Mane. Troy is about love, power, deceit, valour, glory.\"\"\"\r\n\r\ncovid_tweet = \"\"\"As of today, the cumulative number of confirmed #COVID19 cases is 97 302,&nbsp;\r\ntotal number of deaths is 1930 and the total number of recoveries is 51 608.\"\"\"<\/pre>\n<\/div>\n<p>The two strings defined above are <em>multi-line<\/em> strings. Do check the output of movie_review and COVID tweet. First of all, we are going to understand the various methods and the optional flag that can be used in the arguments wherever possible.<\/p>\n<h3>re.compile():<\/h3>\n<p>This method compiles a specified regular expression pattern into a regular expression object, which can be used for matching and searching. We will create two regular expression objects and use them by applying the other methods.<\/p>\n<pre>import re\r\nregex_movie = re.compile('Troy')\r\nregex_covid = re.compile('deaths')\r\nregex_covid<\/pre>\n<p>What output do you notice for regex_covid? Make a note of this!!<\/p>\n<\/div>\n<div>\n<h3>re.match():<\/h3>\n<p>This method is used to match patterns at the beginning of strings. If you pull tweets from Twitter into an excel sheet, you will notice that the twitter handle of the person replied to comes at the beginning of the tweet. This method <em>match<\/em> can be very useful to match a pattern in that case. In continuation of the above-provided code, we execute the following commands on <em>regex_movie<\/em> to find a pattern match.<\/p>\n<div>\n<pre>regex_movie.match(movie_review)\r\nre.match(regex_movie, movie_review)\r\n#Both the above commands do the same task. \r\nOutput - &lt;_sre.SRE_Match object; span=(0, 7), match='Loosely'&gt;\r\n\r\n#Observe the difference in output for the below given commands. \r\n(re.match('troy', movie_review, flags= re.IGNORECASE))\r\n(re.match(regex_movie, movie_review, flags= re.IGNORECASE))<\/pre>\n<\/div>\n<div>The flag IGNORECASE indicates that the match needs to be performed case-insensitively. We can also use re.I also. Further, if we apply match on regex_covid, we get <em>None<\/em> as an output because the pattern is not available at the beginning of the string. You can try this out yourself.<\/div>\n<h3>re.search():<\/h3>\n<p>This method will search the regular expression pattern and return the first occurrence.<\/p>\n<div>\n<pre>re.search('DeaThS', covid_tweet, flags= re.IGNORECASE)\r\nOutput is &lt;_sre.SRE_Match object; span=(107, 113), match='deaths'&gt;<\/pre>\n<\/div>\n<h3>re.findall():<\/h3>\n<p>This method returns <em>all<\/em> non-overlapping matches of the specified regex pattern in the string.<\/p>\n<div>\n<pre>re.findall(r\"^\\w\", movie_review, flags = re.MULTILINE)\r\nre.findall(r\"\\d{2}\", covid_tweet, flags = re.MULTILINE)<\/pre>\n<p>\\w, \\d, {}, ^ are metacharacters. The flag MULTILINE makes $ match the end of a line (not just the end of the string) and makes ^ match the start of any line (not just the start of the string). We can also use re.M. You might revisit this paragraph once we explain these special characters in our metacharacters section in our second part.<\/p>\n<\/div>\n<h3>re.finditer():<\/h3>\n<p>This method returns all matched instances in the form of an iterator, for a specific pattern in a string when scanned from left to right.<\/p>\n<div>\n<pre>for&nbsp;match&nbsp;in&nbsp;re.finditer('troy',&nbsp;movie_review,&nbsp;flags&nbsp;=&nbsp;re.MULTILINE|re.IGNORECASE):\r\n&nbsp;&nbsp;&nbsp; s&nbsp;=&nbsp;match.start()\r\n&nbsp;&nbsp;&nbsp; e&nbsp;=&nbsp;match.end()\r\n&nbsp;&nbsp;&nbsp; g&nbsp;=&nbsp;match.group()\r\n&nbsp;&nbsp;&nbsp; print('Found&nbsp;match&nbsp;\"{}\"&nbsp;ranging&nbsp;from&nbsp;index&nbsp;{}&nbsp;-&nbsp;{}'.format(g,s,e))<\/pre>\n<\/div>\n<\/div>\n<div>\n<pre>Found match \"Troy\" ranging from index 0 - 4\r\nFound match \"Troy\" ranging from index 171 - 175\r\nFound match \"Troy\" ranging from index 275 - 279<\/pre>\n<p>The <em>match<\/em> variable contains a match object. The <code>group()<\/code>method returns the part of the string where there is a match.<br \/>\nThe <code>start()<\/code>function returns the index of the start of the matched substring.<br \/>\nSimilarly, <code>end()<\/code>returns the end index of the matched substring.<\/p>\n<\/div>\n<div>\n<h3>re.sub():<\/h3>\n<p>This method substitutes a specified regex pattern in a string with a replacement string. It only substitutes the left-most occurrence of the pattern in the string.<\/p>\n<div>\n<div>\n<pre>re.sub(\"deaths\",&nbsp;'deaths&nbsp;\ud83d\udc0d',&nbsp;covid_tweet,&nbsp;flags=re.UNICODE)\r\nre.sub(\"[0-9]\", 'x', covid_tweet, flags=re.IGNORECASE)<\/pre>\n<p>The flag UNICODE specifies the Unicode encoding for character classification. We can also use re.U.<\/p>\n<h3>re.subn():<\/h3>\n<\/div>\n<\/div>\n<\/div>\n<div>\n<p>This method is similar to re.sub() except it returns a tuple of 2 items containing the new string and the number of substitutions made. re.subn() is very useful for tasks where we require to know how many replacements are done.<\/p>\n<\/div>\n<div>\n<pre>re.subn(\"[0-9]\",&nbsp;'x',&nbsp;covid_tweet,&nbsp;flags=re.IGNORECASE)<\/pre>\n<h3>re.split():<\/h3>\n<p>The re.split method splits the string where there is a match and returns a list of strings where the splits have occurred. If the pattern from where the split is to happen is not found, re.split() returns a list containing the original string. We can pass the maxsplit argument to the re.split() method. It&#8217;s the maximum number of splits that will occur, 16 in the example command below.<\/p>\n<pre>re.split(',',movie_review,maxsplit=16,flags=re.MULTILINE)<\/pre>\n<h3>Conclusion:<\/h3>\n<p>We have thoroughly explained several regular expression methods and a few useful flag arguments in regular expressions for string manipulations. In the next article, we are going to cover the remaining portions of metacharacters, special sequences, and sets to cover the regular expressions entirely. We will also talk about string formatting to mark the end of basic string operations required for <em>text analytics<\/em>. Do let us know how helpful these tutorials are turning out for you in the comments section. Stay Tuned. Happy Learning!!!<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The very first article in the NLP series introduced Natural Language Processing. We then explained String Operations that can be performed on text using Python. Further, in the quest to strengthen our text pre-processing, we must have a good understanding of Regular Expressions. This article is the first part of a step by step guide of Python Regular expressions. What is Regular Expression? Regular Expressions, also called Reg Exs, are a special sequence of characters often denoted using the raw string notation. Reg Ex helps create string patterns and use them for searching and substituting specific pattern matches in textual data. Many other programming languages like Java, Perl, Unix also support regular expression functionality. Why do we need Regular expression? It is pertinent if you are wondering what is the need for regular expressions. In our previous article, we explained several basic string operations like split, join, strip, etc. Should not these suffice? Let us look at the below scenarios before answering this question. Consider a sample text &#8211; &#8220;N123tur123l l123ngu123ge Processing&#8221;. We want to replace the string &#8216;123&#8217; with &#8216;a&#8217;. A simple string operation code to achieve the task looks like this. string_sample = &#8220;N123tur123l l123ngu123ge Processing&#8221; string_sample.replace(&#8220;123&#8243;,&#8221;a&#8221;) Replaced. [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":9795,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,881,715,552],"tags":[836,840,841,839,837,716,833,321,815,834,835,264,838],"class_list":["post-9775","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-analytics","category-data-science","category-machine-learning-ai","category-technology","tag-compile","tag-findall","tag-finditer","tag-ignorecase","tag-multiline","tag-python","tag-regular-expression","tag-search","tag-split","tag-sub","tag-subn","tag-text-analytics","tag-unicode"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Step By Step Guide to Python Regular Expressions | Ivy Pro School<\/title>\n<meta name=\"description\" content=\"This article is the first part of a step by step guide to Python regular expressions. We have provided some interesting examples for better understanding.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Step By Step Guide to Python Regular Expressions | Ivy Pro School\" \/>\n<meta property=\"og:description\" content=\"This article is the first part of a step by step guide to Python regular expressions. We have provided some interesting examples for better understanding.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/\" \/>\n<meta property=\"og:site_name\" content=\"R vs Python: Which Analytics Tool Should You Choose for Data Science?\" \/>\n<meta property=\"article:author\" content=\"https:\/\/facebook.com\/ivyproschool\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-24T11:41:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-10T10:59:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1080\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ivy Professional School\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ivyproschool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ivy Professional School\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/\"},\"author\":{\"name\":\"Ivy Professional School\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/31fdab8559dd3db99173764bfb60215d\"},\"headline\":\"Step by Step Guide of Python Regular Expressions &#8211; Part 1\",\"datePublished\":\"2020-06-24T11:41:09+00:00\",\"dateModified\":\"2021-06-10T10:59:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/\"},\"wordCount\":1163,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Blog-1.png\",\"keywords\":[\"compile\",\"findall\",\"finditer\",\"IGNORECASE\",\"MULTILINE\",\"python\",\"Regular Expression\",\"search\",\"Split\",\"sub\",\"subn\",\"text analytics\",\"UNICODE\"],\"articleSection\":[\"Data Analytics\",\"Data Science\",\"Machine Learning &amp; AI\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/\",\"name\":\"Step By Step Guide to Python Regular Expressions | Ivy Pro School\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Blog-1.png\",\"datePublished\":\"2020-06-24T11:41:09+00:00\",\"dateModified\":\"2021-06-10T10:59:49+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/31fdab8559dd3db99173764bfb60215d\"},\"description\":\"This article is the first part of a step by step guide to Python regular expressions. We have provided some interesting examples for better understanding.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Blog-1.png\",\"contentUrl\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/Blog-1.png\",\"width\":1080,\"height\":500,\"caption\":\"Python Regular Expressions\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/step-by-step-guide-to-python-regular-expressions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Step by Step Guide of Python Regular Expressions &#8211; Part 1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/\",\"name\":\"Ivy Professional School | Official Blog\",\"description\":\"Confused between R and Python for your data science journey? Discover the key differences in data visualization, handling capabilities, speed, and ease of learning.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/#\\\/schema\\\/person\\\/31fdab8559dd3db99173764bfb60215d\",\"name\":\"Ivy Professional School\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g\",\"caption\":\"Ivy Professional School\"},\"sameAs\":[\"http:\\\/\\\/www.ivyproschool.com\",\"https:\\\/\\\/facebook.com\\\/ivyproschool\",\"https:\\\/\\\/instagram.com\\\/ivyproschool\",\"https:\\\/\\\/x.com\\\/ivyproschool\",\"https:\\\/\\\/youtube.com\\\/ivyproschool\"],\"url\":\"https:\\\/\\\/ivyproschool.com\\\/blog\\\/author\\\/prateek\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Step By Step Guide to Python Regular Expressions | Ivy Pro School","description":"This article is the first part of a step by step guide to Python regular expressions. We have provided some interesting examples for better understanding.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/","og_locale":"en_US","og_type":"article","og_title":"Step By Step Guide to Python Regular Expressions | Ivy Pro School","og_description":"This article is the first part of a step by step guide to Python regular expressions. We have provided some interesting examples for better understanding.","og_url":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/","og_site_name":"R vs Python: Which Analytics Tool Should You Choose for Data Science?","article_author":"https:\/\/facebook.com\/ivyproschool","article_published_time":"2020-06-24T11:41:09+00:00","article_modified_time":"2021-06-10T10:59:49+00:00","og_image":[{"width":1080,"height":500,"url":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-1.png","type":"image\/png"}],"author":"Ivy Professional School","twitter_card":"summary_large_image","twitter_creator":"@ivyproschool","twitter_misc":{"Written by":"Ivy Professional School","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/#article","isPartOf":{"@id":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/"},"author":{"name":"Ivy Professional School","@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/31fdab8559dd3db99173764bfb60215d"},"headline":"Step by Step Guide of Python Regular Expressions &#8211; Part 1","datePublished":"2020-06-24T11:41:09+00:00","dateModified":"2021-06-10T10:59:49+00:00","mainEntityOfPage":{"@id":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/"},"wordCount":1163,"commentCount":0,"image":{"@id":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/#primaryimage"},"thumbnailUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-1.png","keywords":["compile","findall","finditer","IGNORECASE","MULTILINE","python","Regular Expression","search","Split","sub","subn","text analytics","UNICODE"],"articleSection":["Data Analytics","Data Science","Machine Learning &amp; AI","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/","url":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/","name":"Step By Step Guide to Python Regular Expressions | Ivy Pro School","isPartOf":{"@id":"https:\/\/ivyproschool.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/#primaryimage"},"image":{"@id":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/#primaryimage"},"thumbnailUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-1.png","datePublished":"2020-06-24T11:41:09+00:00","dateModified":"2021-06-10T10:59:49+00:00","author":{"@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/31fdab8559dd3db99173764bfb60215d"},"description":"This article is the first part of a step by step guide to Python regular expressions. We have provided some interesting examples for better understanding.","breadcrumb":{"@id":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/#primaryimage","url":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-1.png","contentUrl":"https:\/\/ivyproschool.com\/blog\/wp-content\/uploads\/2015\/08\/Blog-1.png","width":1080,"height":500,"caption":"Python Regular Expressions"},{"@type":"BreadcrumbList","@id":"https:\/\/ivyproschool.com\/blog\/step-by-step-guide-to-python-regular-expressions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ivyproschool.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Step by Step Guide of Python Regular Expressions &#8211; Part 1"}]},{"@type":"WebSite","@id":"https:\/\/ivyproschool.com\/blog\/#website","url":"https:\/\/ivyproschool.com\/blog\/","name":"Ivy Professional School | Official Blog","description":"Confused between R and Python for your data science journey? Discover the key differences in data visualization, handling capabilities, speed, and ease of learning.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ivyproschool.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ivyproschool.com\/blog\/#\/schema\/person\/31fdab8559dd3db99173764bfb60215d","name":"Ivy Professional School","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/866b09293f13d461b399bb9a40607e85623ede13d844f763bf665689cb0d1452?s=96&d=mm&r=g","caption":"Ivy Professional School"},"sameAs":["http:\/\/www.ivyproschool.com","https:\/\/facebook.com\/ivyproschool","https:\/\/instagram.com\/ivyproschool","https:\/\/x.com\/ivyproschool","https:\/\/youtube.com\/ivyproschool"],"url":"https:\/\/ivyproschool.com\/blog\/author\/prateek\/"}]}},"_links":{"self":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/comments?post=9775"}],"version-history":[{"count":1,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9775\/revisions"}],"predecessor-version":[{"id":10566,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/posts\/9775\/revisions\/10566"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/media\/9795"}],"wp:attachment":[{"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/media?parent=9775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/categories?post=9775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ivyproschool.com\/blog\/wp-json\/wp\/v2\/tags?post=9775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}