{"id":3290,"date":"2021-12-07T02:37:21","date_gmt":"2021-12-07T02:37:21","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=3290"},"modified":"2021-12-10T02:06:41","modified_gmt":"2021-12-10T02:06:41","slug":"python-regex-sub","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-sub\/","title":{"rendered":"Python Regex sub()"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn about the Python regex <code>sub()<\/code> function that returns a string after replacing the matched pattern in a string with a replacement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-the-python-regex-sub-function'>Introduction to the Python regex sub function <a href=\"#introduction-to-the-python-regex-sub-function\" class=\"anchor\" id=\"introduction-to-the-python-regex-sub-function\" title=\"Anchor for Introduction to the Python regex sub function\">#<\/a><\/h2>\n\n\n\n<p>The <code>sub()<\/code> is a function in the built-in <code>re<\/code> module that handles <a href=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regular-expressions\/\">regular expressions<\/a>. The <code>sub()<\/code> function has the following syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">re.sub(pattern, repl, string, count=<span class=\"hljs-number\">0<\/span>, flags=<span class=\"hljs-number\">0<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>pattern<\/code> is a regular expression that you want to match. Besides a regular expression, the <code>pattern<\/code> can be  <code>Pattern<\/code> object.<\/li><li><code>repl<\/code> is the replacement<\/li><li><code>string<\/code> is the input string<\/li><li><code>count<\/code> parameter specifies the maximum number of matches that the <code>sub()<\/code> function should replace. If you pass zero to the <code>count<\/code> parameter or completely skip it, the <code>sub()<\/code> function will replace all the matches.<\/li><li><code>flags<\/code> is one or more <a href=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-flags\/\">regex flags<\/a> that modify the standard behavior of the pattern.<\/li><\/ul>\n\n\n\n<p>The <code>sub()<\/code> function searches for the pattern in the string and replaces the matched strings with the replacement (<code>repl<\/code>).<\/p>\n\n\n\n<p>If the <code>sub()<\/code> function couldn&#8217;t find a match, it returns the original string. Otherwise, the <code>sub()<\/code> function returns the string after replacing the matches.<\/p>\n\n\n\n<p>Note that the <code>sub()<\/code> function replaces the leftmost non-overlapping occurrences of the pattern. And you&#8217;ll see it in detail in the following example.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='python-regex-sub-function-examples'>Python regex sub function examples <a href=\"#python-regex-sub-function-examples\" class=\"anchor\" id=\"python-regex-sub-function-examples\" title=\"Anchor for Python regex sub function examples\">#<\/a><\/h2>\n\n\n\n<p>Let&#8217;s take some examples of using the regex <code>sub()<\/code> function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='1-using-the-regex-sub-function-to-return-the-plain-phone-number'>1) Using the regex sub() function to return the plain phone number <a href=\"#1-using-the-regex-sub-function-to-return-the-plain-phone-number\" class=\"anchor\" id=\"1-using-the-regex-sub-function-to-return-the-plain-phone-number\" title=\"Anchor for 1) Using the regex &lt;code&gt;sub()&lt;\/code&gt; function to return the plain phone number\">#<\/a><\/h3>\n\n\n\n<p>The following example uses the <code>sub()<\/code> function to turn the phone number <code>(212)-456-7890<\/code> into <code>2124567890<\/code> :<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\nphone_no = <span class=\"hljs-string\">'(212)-456-7890'<\/span>\npattern = <span class=\"hljs-string\">'\\D'<\/span>\nresult = re.sub(pattern, <span class=\"hljs-string\">''<\/span>,phone_no)\n\nprint(result)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-number\">2124567890<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, the <code>\\D<\/code> is an inverse digit <a href=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-character-set\/\">character set<\/a> that matches any single character which is not a digit. Therefore, the <code>sub()<\/code> function replaces all non-digit characters with the empty string <code>''<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='2-using-the-regex-sub-function-to-replace-the-leftmost-non-overlapping-occurrences-of-a-pattern'>2) Using the regex sub() function to replace the leftmost non-overlapping occurrences of a pattern <a href=\"#2-using-the-regex-sub-function-to-replace-the-leftmost-non-overlapping-occurrences-of-a-pattern\" class=\"anchor\" id=\"2-using-the-regex-sub-function-to-replace-the-leftmost-non-overlapping-occurrences-of-a-pattern\" title=\"Anchor for 2) Using the regex &lt;code&gt;sub()&lt;\/code&gt; function to replace the leftmost non-overlapping occurrences of a pattern\">#<\/a><\/h3>\n\n\n\n<p>The following example replaces the <code>00<\/code> with the <code>''<\/code> in the string <code>'000000'<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\npattern = <span class=\"hljs-string\">'00'<\/span>\ns = <span class=\"hljs-string\">'00000'<\/span>\nresult = re.sub(pattern,<span class=\"hljs-string\">''<\/span>,s)\n\nprint(result)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-number\">0<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, we replace two zeros with empty strings. So the first two are matched and replaced, then the following two zeroes are matches and replaced too, and finally, the last digit remains unchanged. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='3-using-the-regex-sub-with-a-backreference-example'>3) Using the regex sub() with a backreference example <a href=\"#3-using-the-regex-sub-with-a-backreference-example\" class=\"anchor\" id=\"3-using-the-regex-sub-with-a-backreference-example\" title=\"Anchor for 3) Using the regex &lt;code&gt;sub()&lt;\/code&gt; with a backreference example\">#<\/a><\/h3>\n\n\n\n<p>The following example uses the <code>sub()<\/code> function to replace the text surrounded with (<code>*<\/code>) (it&#8217;s markdown format by the way) with the <code>&lt;b&gt;<\/code> tag in HTML:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\ns = <span class=\"hljs-string\">'Make the World a *Better Place*'<\/span>\npattern = <span class=\"hljs-string\">r'\\*(.*?)\\*'<\/span>\nreplacement = <span class=\"hljs-string\">r'&lt;b&gt;\\1&lt;\\\\b&gt;'<\/span>\nhtml = re.sub(pattern, replacement, s)\n\nprint(html)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\ns = <span class=\"hljs-string\">'Make the World a *Better Place*'<\/span>\npattern = <span class=\"hljs-string\">r'\\*(.*?)\\*'<\/span>\nreplacement = <span class=\"hljs-string\">r'&lt;b&gt;\\1&lt;\\\\b&gt;'<\/span>\nhtml = re.sub(pattern, replacement, s)\n\nprint(html)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">Make the World a &lt;b&gt;Better Place&lt;\\b&gt;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, the pattern <code>r'\\*(.*?)\\*'<\/code> find the text that begins and ends with the asterisk (<code>*<\/code>). It has a capturing group that captures the text between asterisks (<code>*<\/code>).<\/p>\n\n\n\n<p>The replacement is a regular expression with a <a href=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-backreferences\/\">backreference<\/a>. The backreference <code>\\1<\/code> refers to the first group in the pattern, which is the text between the asterisks (<code>*<\/code>).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='4-using-the-regex-sub-function-with-the-replacement-as-a-function'>4) Using the regex sub() function with the replacement as a function <a href=\"#4-using-the-regex-sub-function-with-the-replacement-as-a-function\" class=\"anchor\" id=\"4-using-the-regex-sub-function-with-the-replacement-as-a-function\" title=\"Anchor for 4) Using the regex &lt;code&gt;sub()&lt;\/code&gt; function with the replacement as a function\">#<\/a><\/h3>\n\n\n\n<p>Suppose you have a list of strings where each element contain both alphabet and number:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">l = &#91;<span class=\"hljs-string\">'A1'<\/span>,<span class=\"hljs-string\">'A2'<\/span>,<span class=\"hljs-string\">'A3'<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And you want to square the number in each list element. For example, A1 becomes A1, A2 becomes A4, and A3 becomes A9. To do this, you can use the <code>sub()<\/code> function.<\/p>\n\n\n\n<p>The second argument of the <code>sub()<\/code> function (<code>repl<\/code>) can be a function. In this case, the <code>sub()<\/code> function will call this function for every non-overlapping occurrence of the pattern. <\/p>\n\n\n\n<p>This function (<code>repl<\/code>) takes a single <code>Match<\/code> object argument and returns the replacement string.<\/p>\n\n\n\n<p>The following illustrates how to use the second argument as a function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">square<\/span><span class=\"hljs-params\">(match)<\/span>:<\/span>\n    num = int(match.group())\n    <span class=\"hljs-keyword\">return<\/span> str(num*num)\n\nl = &#91;<span class=\"hljs-string\">'A1'<\/span>,<span class=\"hljs-string\">'A2'<\/span>,<span class=\"hljs-string\">'A3'<\/span>]\npattern = <span class=\"hljs-string\">r'\\d+'<\/span>\nnew_l = &#91;re.sub(pattern, square, s) <span class=\"hljs-keyword\">for<\/span> s <span class=\"hljs-keyword\">in<\/span> l]\n\nprint(new_l)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">&#91;<span class=\"hljs-string\">'A1'<\/span>, <span class=\"hljs-string\">'A4'<\/span>, <span class=\"hljs-string\">'A9'<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>How it works.<\/p>\n\n\n\n<p>First, define a list of strings:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">l = &#91;<span class=\"hljs-string\">'A1'<\/span>,<span class=\"hljs-string\">'A2'<\/span>,<span class=\"hljs-string\">'A3'<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, define a pattern <code>\\d+<\/code> that match one or more digits:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">pattern = <span class=\"hljs-string\">r'\\d+'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, replace the digits with their squares by calling the <code>sub()<\/code> function and passing the <code>square()<\/code> function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">new_l = &#91;re.sub(pattern, square, s) <span class=\"hljs-keyword\">for<\/span> s <span class=\"hljs-keyword\">in<\/span> l]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Finally, define the <code>square()<\/code> function that squares the matched digit and returns it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">square<\/span><span class=\"hljs-params\">(match)<\/span>:<\/span>\n    num = int(match.group())\n    <span class=\"hljs-keyword\">return<\/span> str(num*num)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Use the Python regex <code><code>sub()<\/code><\/code> function to replace the occurrences of matches of a pattern with a replacement.<\/li><\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"3290\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-sub\/\"\n\t\t\t\tdata-post-title=\"Python Regex sub()\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"3290\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-sub\/\"\n\t\t\t\tdata-post-title=\"Python Regex sub()\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\t\t\t<input type=\"button\" name=\"wth-submit\" class=\"wth-btn wth-btn-submit\" id=\"wth-submit\" \/>\n\t\t\t<input type=\"button\" class=\"wth-btn wth-btn-cancel\" value=\"Cancel\" \/>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn about the Python regex sub() function that returns a string after replacing the matched pattern in a string with the replacements.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3122,"menu_order":19,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3290","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/3290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/comments?post=3290"}],"version-history":[{"count":0,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/3290\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/3122"}],"wp:attachment":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media?parent=3290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}