{"id":254,"date":"2022-10-04T12:43:53","date_gmt":"2022-10-04T04:43:53","guid":{"rendered":"https:\/\/islandtropicaman.com\/wp\/?p=254"},"modified":"2022-10-04T12:45:36","modified_gmt":"2022-10-04T04:45:36","slug":"python-regex-module","status":"publish","type":"post","link":"https:\/\/islandtropicaman.com\/wp\/2022\/10\/04\/python-regex-module\/","title":{"rendered":"Python RegEx Module"},"content":{"rendered":"<p>In this chapter let us create a few examples with Python built-in RegEx module&#8217;s methods and see what this particular module can do!<\/p>\n<p>As always, you need to import the module into your python file before using it.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nimport re\r\n<\/pre>\n<p>Find whether a phrase is contained within a string or not and uses case insensitive search.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\ntext = &quot;Well, again, it is Hello WORLD!...&quot;\r\nresult = (re.match(&quot;.*Hello World.*&quot;, text, re.I))\r\n<\/pre>\n<p>Below is the return Match object.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;re.Match object; span=(0, 34), match='Well, again, it is Hello WORLD!...'&gt;\r\n<\/pre>\n<p>Which shows it matches our search.<\/p>\n<p>Besides using to search a string, re module also can be used to split the text into a list. The below line will split the text into a list at each white-space character.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\ntext = &quot;Well, again, it is Hello WORLD!...&quot;\r\nresult = re.split(&quot;\\s&quot;, text) # &#x5B;'Well,', 'again,', 'it', 'is', 'Hello', 'WORLD!...']\r\n<\/pre>\n<p>At last, let us replaced hello world with a good morning phrase.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\ntext = &quot;Well, again, it is Hello WORLD!...&quot;\r\nresult = re.sub(&quot;Hello WORLD&quot;, &quot;good morning&quot;, text) # Well, again, it is good morning!...\r\n<\/pre>\n<p>There is still more to learn from this module which I will leave to you all to explore by yourself.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this chapter let us create a few examples with Python built-in RegEx module&#8217;s methods and see what this particular module can do! As always, you need to import the module into your python file before using it. import re Find whether a phrase is contained within a string or not and uses case insensitive&#8230;<\/p>\n<p class=\"more-link-wrap\"><a href=\"https:\/\/islandtropicaman.com\/wp\/2022\/10\/04\/python-regex-module\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &ldquo;Python RegEx Module&rdquo;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,72],"tags":[74],"class_list":["post-254","post","type-post","status-publish","format-standard","hentry","category-python","category-python-tutorial","tag-re"],"blog_post_layout_featured_media_urls":{"thumbnail":"","full":""},"categories_names":{"8":{"name":"Python","link":"https:\/\/islandtropicaman.com\/wp\/category\/python\/"},"72":{"name":"Python Tutorial","link":"https:\/\/islandtropicaman.com\/wp\/category\/python-tutorial\/"}},"tags_names":{"74":{"name":"re","link":"https:\/\/islandtropicaman.com\/wp\/tag\/re\/"}},"comments_number":"0","_links":{"self":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/comments?post=254"}],"version-history":[{"count":2,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/254\/revisions"}],"predecessor-version":[{"id":256,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/254\/revisions\/256"}],"wp:attachment":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/media?parent=254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/categories?post=254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/tags?post=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}