<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Python - Regular Expressions - Tutorialspoint</title>
<meta charset="utf-8">
<meta name="description" content="Python - Regular Expressions - A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pat"/>
<meta name="keywords" content="C, C++, Python, Java, HTML, CSS, JavaScript, SQL, PHP, jQuery, XML, DOM, Bootstrap, Tutorials, Articles, Programming, training, learning, quiz, preferences, examples, code"/>
<link rel="canonical" href="https://www.tutorialspoint.com/python/python_reg_expressions.htm" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=yes">
<link rel="stylesheet" href="/themes/css/style-min-v1.css?v=3.1.2.336">
<script src="/themes/js/script-min-v1.js?v=3.0.2040229"></script>
<script>
function printPage() { window.print(); }
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
</script>
<script id="adp1" data-cfasync="false" type="text/javascript">(function(w, d) { var s = d.createElement('script'); s.src = '//cdn.adpushup.com/40046/adpushup.js'; s.type = 'text/javascript'; s.async = true; (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); })(window, document);</script>
<script id="adp2" data-cfasync="false" type="text/javascript">(function(w, d) {var cval = readCookie('subscription_purchased');if(cval == '1'){ return; } var s = d.createElement('script'); s.src = '//delivery.adrecover.com/18107/adRecover.js'; s.type = 'text/javascript'; s.async = true; (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); })(window, document);</script>
<style>
.butnn-save a{color:#fff;} .notes_msg{color:green; margin-left:20px; margin-top:15px;}
.right-menu .mui-btn {
background-color:#fdbf00;
}
a.demo {
background:#fdbf00;
}
li.heading {
background:#fdbf00;
}
.course-box{background:#fdbf00}
.home-intro-sub p{color:#fdbf00}
a.demo{
top: 12px;
float:right;
}
.prettyprint{
width: 99%;
}
pre.prettyprint.tryit {min-height:37px; background: #eee url(/python/images/try-it.jpg) top right no-repeat !important}</style>
</head>
<body>
<header id="header">
<!-- pop-up -->
<div class="pop-modal overlay-pop popdiv">
<div class="modal-window small">
<span class="close" title="close">×</span>
<div class="pop-content">
</div>
<span class="msg" ></span>
</div>
</div>
<div class="wrap_loader">
<div class="imgLoader"><img src="/videotutorials/images/loader.gif" alt="Tutorialspoint" width="70" height="70"></div>
</div>
<input type="hidden" id="vu" name="vu" value="" />
<!-- pop-up -->
<!-- Top sub-menu Starts Here -->
<div class="mui-appbar mui-container-fulid top-menu">
<div class="mui-container">
<div class="top-menu-item home">
<a href="https://www.tutorialspoint.com/index.htm" target="_blank" title="TutorialsPoint - Home"><i class="fal fa-home"></i> <span>Home</span></a>
</div>
<div class="top-menu-item qa">
<a href="https://www.tutorialspoint.com/about/about_careers.htm" target="_blank" title="Job @ Tutorials Point"><i class="fa fa-suitcase"></i> <span>Jobs</span></a>
</div>
<div class="top-menu-item tools">
<a href="https://www.tutorialspoint.com/online_dev_tools.htm" target="_blank" title="Tools - Online Development and Testing Tools"><i class="fal fa-cogs"></i> <span>Tools</span></a>
</div>
<div class="top-menu-item coding-ground">
<a href="https://www.tutorialspoint.com/codingground.htm" target="_blank" title="Coding Ground - Free Online IDE and Terminal"><i class="fal fa-code"></i> <span>Coding Ground </span></a>
</div>
<div class="top-menu-item current-affairs">
<a href="https://www.tutorialspoint.com/current_affairs.htm" target="_blank" title="Daily Current Affairs"><i class="fal fa-layer-plus"></i> <span>Current Affairs</span></a>
</div>
<div class="top-menu-item upsc-notes">
<a href="https://www.tutorialspoint.com/upsc_ias_exams.htm" target="_blank" title="UPSC IAS Exams Notes - TutorialsPoint"><i class="fal fa-user-tie"></i> <span>UPSC Notes</span></a>
</div>
<div class="top-menu-item articles">
<a href="https://www.tutorialspoint.com/tutor_connect/index.php" target="_blank" title="Top Online Tutors - Tutor Connect"><i class="fal fa-user"></i> <span>Online Tutors</span></a>
</div>
<div class="top-menu-item whiteboard">
<a href="https://www.tutorialspoint.com/whiteboard.htm" target="_blank" title="Free Online Whiteboard"><i class="fal fa-chalkboard"></i> <span>Whiteboard</span></a>
</div>
<div class="top-menu-item net-meeting">
<a href="https://www.tutorialspoint.com/netmeeting.php" target="_blank" title="A free tool for online video conferencing"><i class="fal fa-chalkboard-teacher"></i> <span>Net Meeting</span></a>
</div>
<div class="top-menu-item articles">
<a href="https://www.tutorix.com" target="_blank" title="Tutorx - The Best Learning App" rel="nofollow"><i class="fal fa-video"></i> <span>Tutorix</span></a>
</div>
<div class="top-menu-item qa login">
<a href="/videotutorials/login.php" target="_blank" title="Tutorials Point - Login"><i class="fa fa-sign-in-alt"></i> <span>Login</span></a>
</div>
<div class="top-menu-item qa login">
<a href="/videotutorials/subscription.php" target="_blank" title="Paid Package"><i class="fa fa-book-reader"></i> <span>Packages</span></a>
</div>
<div class="social-menu-item">
<a href="https://www.facebook.com/tutorialspointindia" target="_blank" rel="nofollow" data-placement="bottom" title="tutorialspoint @ Facebook"><i class="fab fa-facebook-f"></i></a>
<a href="https://www.twitter.com/tutorialspoint" target="_blank" rel="nofollow" data-placement="bottom" title="tutorialspoint @ Twitter"><i class="fab fa-twitter"></i></a>
<a href="https://www.linkedin.com/company/tutorialspoint" target="_blank" rel="nofollow" data-placement="bottom" title="tutorialspoint @ Linkedin"><i class="fab fa-linkedin-in"></i></a>
<a href="https://www.youtube.com/channel/UCVLbzhxVTiTLiVKeGV7WEBg" target="_blank" rel="nofollow" data-placement="bottom" title="tutorialspoint YouTube"><i class="fab fa-youtube"></i></a>
</div>
</div>
</div>
<!-- Top sub-menu Ends Here -->
<!-- Top main-menu Starts Here -->
<div class="mui-appbar mui-container-fulid mui--appbar-line-height mui--z1" id="logo-menu">
<div class="mui-container">
<div class="left-menu">
<a href="https://www.tutorialspoint.com/index.htm" title="Tutorialspoint">
<img class="tp-logo" alt="tutorialspoint" src="/python/images/logo.png">
</a>
<div class="mui-dropdown">
<a class="mui-btn mui-btn--primary categories" data-mui-toggle="dropdown"><i class="fa fa-th-large"></i>
<span>Categories <span class="mui-caret"></span></span></a>
<ul class="mui-dropdown__menu cat-menu">
<li>
<ul>
<li><a href="/academic_tutorials.htm"><i class="fa fa-caret-right"></i> Academic Tutorials</a></li>
<li><a href="/big_data_tutorials.htm"><i class="fa fa-caret-right"></i> Big Data & Analytics </a></li>
<li><a href="/computer_programming_tutorials.htm"><i class="fa fa-caret-right"></i> Computer Programming </a></li>
<li><a href="/computer_science_tutorials.htm"><i class="fa fa-caret-right"></i> Computer Science </a></li>
<li><a href="/database_tutorials.htm"><i class="fa fa-caret-right"></i> Databases </a></li>
<li><a href="/devops_tutorials.htm"><i class="fa fa-caret-right"></i> DevOps </a></li>
<li><a href="/digital_marketing_tutorials.htm"><i class="fa fa-caret-right"></i> Digital Marketing </a></li>
<li><a href="/engineering_tutorials.htm"><i class="fa fa-caret-right"></i> Engineering Tutorials </a></li>
<li><a href="/upsc_ias_exams.htm"><i class="fa fa-caret-right"></i> Exams Syllabus </a></li>
<li><a href="/famous_monuments.htm"><i class="fa fa-caret-right"></i> Famous Monuments </a></li>
<li><a href="/gate_exams_tutorials.htm"><i class="fa fa-caret-right"></i> GATE Exams Tutorials</a></li>
<li><a href="/latest_technologies.htm"><i class="fa fa-caret-right"></i> Latest Technologies </a></li>
<li><a href="/machine_learning_tutorials.htm"><i class="fa fa-caret-right"></i> Machine Learning </a></li>
<li><a href="/mainframe_tutorials.htm"><i class="fa fa-caret-right"></i> Mainframe Development </a></li>
<li><a href="/management_tutorials.htm"><i class="fa fa-caret-right"></i> Management Tutorials </a></li>
<li><a href="/maths_tutorials.htm"><i class="fa fa-caret-right"></i> Mathematics Tutorials</a></li>
<li><a href="/microsoft_technologies_tutorials.htm"><i class="fa fa-caret-right"></i> Microsoft Technologies </a></li>
<li><a href="/misc_tutorials.htm"><i class="fa fa-caret-right"></i> Misc tutorials </a></li>
<li><a href="/mobile_development_tutorials.htm"><i class="fa fa-caret-right"></i> Mobile Development </a></li>
<li><a href="/java_technology_tutorials.htm"><i class="fa fa-caret-right"></i> Java Technologies </a></li>
<li><a href="/python_technologies_tutorials.htm"><i class="fa fa-caret-right"></i> Python Technologies </a></li>
<li><a href="/sap_tutorials.htm"><i class="fa fa-caret-right"></i> SAP Tutorials </a></li>
<li><a href="/scripting_lnaguage_tutorials.htm"><i class="fa fa-caret-right"></i>Programming Scripts </a></li>
<li><a href="/selected_reading.htm"><i class="fa fa-caret-right"></i> Selected Reading </a></li>
<li><a href="/software_quality_tutorials.htm"><i class="fa fa-caret-right"></i> Software Quality </a></li>
<li><a href="/soft_skill_tutorials.htm"><i class="fa fa-caret-right"></i> Soft Skills </a></li>
<li><a href="/telecom_tutorials.htm"><i class="fa fa-caret-right"></i> Telecom Tutorials </a></li>
<li><a href="/upsc_ias_exams.htm"><i class="fa fa-caret-right"></i> UPSC IAS Exams </a></li>
<li><a href="/web_development_tutorials.htm"><i class="fa fa-caret-right"></i> Web Development </a></li>
<li><a href="/sports_tutorials.htm"><i class="fa fa-caret-right"></i> Sports Tutorials </a></li>
<li><a href="/xml_technologies_tutorials.htm"><i class="fa fa-caret-right"></i> XML Technologies </a></li>
<li><a href="/multi_language_tutorials.htm"><i class="fa fa-caret-right"></i> Multi-Language</a></li>
<li><a href="/questions_and_answers.htm"><i class="fa fa-caret-right"></i> Interview Questions</a></li>
</ul>
</li>
</ul>
<div class="clear"></div>
</div>
</div>
<div class="right-menu">
<div class="toc-toggle">
<a href="javascript:void(0);"><i class="fa fa-bars"></i></a>
</div>
<div class="mobile-search-btn">
<a href="https://www.tutorialspoint.com/index.htm"><i class="fal fa-search"></i></a>
</div>
<div class="search-box">
<script async src="https://cse.google.com/cse.js?cx=000263362972888060243:yfed6eu421q"></script>
<div class='gcse-search'></div>
</div>
<div class="menu-btn library-btn">
<a href="https://www.tutorialspoint.com/tutorialslibrary.htm"><i class="fal fa-cubes"></i> <span>Library</span></a>
</div>
<div class="menu-btn videos-btn">
<a href="https://www.tutorialspoint.com/videotutorials/index.php"><i class="fal fa-video"></i> <span>Videos</span></a>
</div>
<div class="menu-btn videos-btn">
<a href="https://www.tutorialspoint.com/questions/index.php"><i class="fa fa-location-arrow"></i> <span>Q/A</span></a>
</div>
<div class="menu-btn ebooks-btn">
<a href="https://store.tutorialspoint.com"><i class="fal fa-book"></i> <span>eBooks</span></a>
</div>
<div class="mui-dropdown">
<button class="mui-btn mui-btn--primary mobile-menu" data-mui-toggle="dropdown">
<span class="mui-caret"></span>
</button>
<ul class="mui-dropdown__menu">
<li class="login"><a href="https://www.tutorialspoint.com/videotutorials/login.php"><i class="fal fa-sign-in-alt"></i> <span>Login</span></a></li>
<li><a href="https://www.tutorialspoint.com/tutorialslibrary.htm"><i class="fal fa-cubes"></i> <span>Library</span></a></li>
<li><a href="https://www.tutorialspoint.com/videotutorials/index.php"><i class="fal fa-video"></i> <span>Videos</span></a></li>
<li><a href="https://store.tutorialspoint.com"><i class="fal fa-book"></i> <span>eBooks</span></a></li>
</ul>
</div>
</div>
</div>
</div>
<!-- Top main-menu Ends Here -->
</header>
<div class="mui-container-fluid content">
<div class="mui-container">
<!-- Tutorial ToC Starts Here -->
<div class="mui-col-md-3 tutorial-toc">
<div class="mini-logo">
<img src="/python/images/python-mini.jpg" alt="Python Tutorial" />
</div>
<ul class="toc chapters">
<li class="heading">Python Basic Tutorial</li>
<li><a target="_top" href="/python/index.htm">Python - Home</a></li>
<li><a target="_top" href="/python/python_overview.htm">Python - Overview</a></li>
<li><a target="_top" href="/python/python_environment.htm">Python - Environment Setup</a></li>
<li><a target="_top" href="/python/python_basic_syntax.htm">Python - Basic Syntax</a></li>
<li><a target="_top" href="/python/python_variable_types.htm">Python - Variable Types</a></li>
<li><a target="_top" href="/python/python_basic_operators.htm">Python - Basic Operators</a></li>
<li><a target="_top" href="/python/python_decision_making.htm">Python - Decision Making</a></li>
<li><a target="_top" href="/python/python_loops.htm">Python - Loops</a></li>
<li><a target="_top" href="/python/python_numbers.htm">Python - Numbers</a></li>
<li><a target="_top" href="/python/python_strings.htm">Python - Strings</a></li>
<li><a target="_top" href="/python/python_lists.htm">Python - Lists</a></li>
<li><a target="_top" href="/python/python_tuples.htm">Python - Tuples</a></li>
<li><a target="_top" href="/python/python_dictionary.htm">Python - Dictionary</a></li>
<li><a target="_top" href="/python/python_date_time.htm">Python - Date & Time</a></li>
<li><a target="_top" href="/python/python_functions.htm">Python - Functions</a></li>
<li><a target="_top" href="/python/python_modules.htm">Python - Modules</a></li>
<li><a target="_top" href="/python/python_files_io.htm">Python - Files I/O</a></li>
<li><a target="_top" href="/python/python_exceptions.htm">Python - Exceptions</a></li>
</ul>
<ul class="toc chapters">
<li class="heading">Python Advanced Tutorial</li>
<li><a target="_top" href="/python/python_classes_objects.htm">Python - Classes/Objects</a></li>
<li><a target="_top" href="/python/python_reg_expressions.htm">Python - Reg Expressions</a></li>
<li><a target="_top" href="/python/python_cgi_programming.htm">Python - CGI Programming</a></li>
<li><a target="_top" href="/python/python_database_access.htm">Python - Database Access</a></li>
<li><a target="_top" href="/python/python_networking.htm">Python - Networking</a></li>
<li><a target="_top" href="/python/python_sending_email.htm">Python - Sending Email</a></li>
<li><a target="_top" href="/python/python_multithreading.htm">Python - Multithreading</a></li>
<li><a target="_top" href="/python/python_xml_processing.htm">Python - XML Processing</a></li>
<li><a target="_top" href="/python/python_gui_programming.htm">Python - GUI Programming</a></li>
<li><a target="_top" href="/python/python_further_extensions.htm">Python - Further Extensions</a></li>
</ul>
<ul class="toc chapters">
<li class="heading">Python Useful Resources</li>
<li><a target="_top" href="/python/python_questions_answers.htm">Python - Questions and Answers</a></li>
<li><a target="_top" href="/python/python_quick_guide.htm">Python - Quick Guide</a></li>
<li><a target="_top" href="/python/python_tools_utilities.htm">Python - Tools/Utilities</a></li>
<li><a target="_top" href="/python/python_useful_resources.htm">Python - Useful Resources</a></li>
<li><a target="_top" href="/python/python_discussion.htm">Python - Discussion</a></li>
</ul>
<ul class="toc reading">
<li class="sreading">Selected Reading</li>
<li><a target="_top" href="/upsc_ias_exams.htm">UPSC IAS Exams Notes</a></li>
<li><a target="_top" href="/developers_best_practices/index.htm">Developer's Best Practices</a></li>
<li><a target="_top" href="/questions_and_answers.htm">Questions and Answers</a></li>
<li><a target="_top" href="/effective_resume_writing.htm">Effective Resume Writing</a></li>
<li><a target="_top" href="/hr_interview_questions/index.htm">HR Interview Questions</a></li>
<li><a target="_top" href="/computer_glossary.htm">Computer Glossary</a></li>
<li><a target="_top" href="/computer_whoiswho.htm">Who is Who</a></li>
</ul>
<div id="stickyparent">
<div style="height:250px;width:300px;" id="sticky-ad">
<div id="430c9911-782f-495d-88f9-69f58ca8c9a4" class="_ap_apex_ad" >
<script>
var adpushup = adpushup || {};
adpushup.que = adpushup.que || [];
adpushup.que.push(function() {
adpushup.triggerAd("430c9911-782f-495d-88f9-69f58ca8c9a4");
});
</script>
</div>
</div>
</div>
</div>
<!-- Tutorial ToC Ends Here -->
<!-- Tutorial Content Starts Here -->
<div class="mui-col-md-6 tutorial-content">
<h1>Python - Regular Expressions</h1>
<hr />
<div id="google-top-ads">
<div class="top-ad-heading">Advertisements</div>
<div style="text-align:center" class="google-top-ads">
<div id="adp_top_ads" style="text-align:center!important;min-height:90px!important"></div>
<script>
var adPos = document.getElementById('adp_top_ads');
var ad_id_720 = "8014640d-fd34-4b2e-9b1b-cc67234a2325";
var ad_id_650 = "2d1bb2c4-eb72-471d-9c80-1bf5514728c1";
var ad_id_300 = "df94a1a9-ae2f-432d-9a92-d93823ff4503";
var width = window.innerWidth;
var ad_id = ad_id_720;
if( width <= 768 ){
ad_id = ad_id_300;
}else if( width <= 1435 ){
ad_id = ad_id_650;
}
adPos.innerHTML = '<div id="' + ad_id + '" class="_ap_apex_ad"></div>';
var adpushup = adpushup || {};
adpushup.que = adpushup.que || [];
adpushup.que.push(function() {
adpushup.triggerAd(ad_id);
});
</script>
</div>
</div>
<br>
<div class="mui-container-fluid button-borders">
<div class="pre-btn">
<a href="/python/python_classes_objects.htm"><i class="fal fa-chevron-circle-left"></i> Previous Page</a>
</div>
<div class="nxt-btn">
<a href="/python/python_cgi_programming.htm">Next Page <i class="fal fa-chevron-circle-right"></i> </a>
</div>
</div>
<div class="clearer"></div>
<p>A <i>regular expression</i> is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern. Regular expressions are widely used in UNIX world.</p>
<p>The Python module <b>re</b> provides full support for Perl-like regular expressions in Python. The re module raises the exception re.error if an error occurs while compiling or using a regular expression.</p>
<p>We would cover two important functions, which would be used to handle regular expressions. But a small thing first: There are various characters, which would have special meaning when they are used in regular expression. To avoid any confusion while dealing with regular expressions, we would use Raw Strings as <b>r'expression'</b>.</p>
<h2>The <i>match</i> Function</h2>
<p>This function attempts to match RE <i>pattern</i> to <i>string</i> with optional <i>flags</i>.</p>
<p>Here is the syntax for this function −</p>
<pre class="result notranslate">
re.match(pattern, string, flags=0)
</pre>
<p>Here is the description of the parameters −</p>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Parameter & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>pattern</b></p>
<p>This is the regular expression to be matched.</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>string</b></p>
<p>This is the string, which would be searched to match the pattern at the beginning of string.</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td><p><b>flags</b></p>
<p>You can specify different flags using bitwise OR (|). These are modifiers, which are listed in the table below.</p></td>
</tr>
</table>
<p>The <i>re.match</i> function returns a <b>match</b> object on success, <b>None</b> on failure. We use<i>group(num)</i> or <i>groups() </i> function of <b>match</b> object to get matched expression.</p>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Match Object Method & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>group(num=0)</b></p>
<p>This method returns entire match (or specific subgroup num)</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>groups()</b></p>
<p>This method returns all matching subgroups in a tuple (empty if there weren't any)</p></td>
</tr>
</table>
<h3>Example</h3>
<div class="demo-view">
<a href="http://tpcg.io/cZGpLX" target="_blank" rel="nofollow" class="demo"><i class="fa-external-link"></i> Live Demo</a>
</div>
<pre class="prettyprint notranslate">
#!/usr/bin/python
import re
line = "Cats are smarter than dogs"
matchObj = re.match( r'(.*) are (.*?) .*', line, re.M|re.I)
if matchObj:
print "matchObj.group() : ", matchObj.group()
print "matchObj.group(1) : ", matchObj.group(1)
print "matchObj.group(2) : ", matchObj.group(2)
else:
print "No match!!"
</pre>
<p>When the above code is executed, it produces following result −</p>
<pre class="result notranslate">
matchObj.group() : Cats are smarter than dogs
matchObj.group(1) : Cats
matchObj.group(2) : smarter
</pre>
<h2>The <i>search</i> Function</h2>
<p>This function searches for first occurrence of RE <i>pattern</i> within <i>string</i> with optional <i>flags</i>.</p>
<p>Here is the syntax for this function −</p>
<pre class="result notranslate">
re.search(pattern, string, flags=0)
</pre>
<p>Here is the description of the parameters −</p>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Parameter & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>pattern</b></p>
<p>This is the regular expression to be matched.</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>string</b></p>
<p>This is the string, which would be searched to match the pattern anywhere in the string.</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td><p><b>flags</b></p>
<p>You can specify different flags using bitwise OR (|). These are modifiers, which are listed in the table below.</p></td>
</tr>
</table>
<p>The <i>re.search</i> function returns a <b>match</b> object on success, <b>none</b> on failure. We use <i>group(num) </i> or <i>groups() </i> function of <b>match</b> object to get matched expression.</p>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Match Object Methods & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>group(num=0)</b></p>
<p>This method returns entire match (or specific subgroup num)</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>groups()</b></p>
<p>This method returns all matching subgroups in a tuple (empty if there weren't any)</p></td>
</tr>
</table>
<h3>Example</h3>
<div class="demo-view">
<a href="http://tpcg.io/WE021A" target="_blank" rel="nofollow" class="demo"><i class="fa-external-link"></i> Live Demo</a>
</div>
<pre class="prettyprint notranslate">
#!/usr/bin/python
import re
line = "Cats are smarter than dogs";
searchObj = re.search( r'(.*) are (.*?) .*', line, re.M|re.I)
if searchObj:
print "searchObj.group() : ", searchObj.group()
print "searchObj.group(1) : ", searchObj.group(1)
print "searchObj.group(2) : ", searchObj.group(2)
else:
print "Nothing found!!"
</pre>
<p>When the above code is executed, it produces following result −</p>
<pre class="result notranslate">
searchObj.group() : Cats are smarter than dogs
searchObj.group(1) : Cats
searchObj.group(2) : smarter
</pre>
<h2>Matching Versus Searching</h2>
<p>Python offers two different primitive operations based on regular expressions: <b>match</b> checks for a match only at the beginning of the string, while <b>search</b> checks for a match anywhere in the string (this is what Perl does by default).</p>
<h3>Example</h3>
<div class="demo-view">
<a href="http://tpcg.io/1VpZ8k" target="_blank" rel="nofollow" class="demo"><i class="fa-external-link"></i> Live Demo</a>
</div>
<pre class="prettyprint notranslate">
#!/usr/bin/python
import re
line = "Cats are smarter than dogs";
matchObj = re.match( r'dogs', line, re.M|re.I)
if matchObj:
print "match --> matchObj.group() : ", matchObj.group()
else:
print "No match!!"
searchObj = re.search( r'dogs', line, re.M|re.I)
if searchObj:
print "search --> searchObj.group() : ", searchObj.group()
else:
print "Nothing found!!"
</pre>
<p>When the above code is executed, it produces the following result −</p>
<pre class="result notranslate">
No match!!
search --> searchObj.group() : dogs
</pre>
<h2>Search and Replace</h2>
<p>One of the most important <b>re</b> methods that use regular expressions is <b>sub</b>.</p>
<h3>Syntax</h3>
<pre class="result notranslate">
re.sub(pattern, repl, string, max=0)
</pre>
<p>This method replaces all occurrences of the RE <i>pattern</i> in <i>string</i> with <i>repl</i>, substituting all occurrences unless <i>max</i> provided. This method returns modified string.</p>
<h3>Example</h3>
<div class="demo-view">
<a href="http://tpcg.io/jVaoEQ" target="_blank" rel="nofollow" class="demo"><i class="fa-external-link"></i> Live Demo</a>
</div>
<pre class="prettyprint notranslate">
#!/usr/bin/python
import re
phone = "2004-959-559 # This is Phone Number"
# Delete Python-style comments
num = re.sub(r'#.*$', "", phone)
print "Phone Num : ", num
# Remove anything other than digits
num = re.sub(r'\D', "", phone)
print "Phone Num : ", num
</pre>
<p>When the above code is executed, it produces the following result −</p>
<pre class="result notranslate">
Phone Num : 2004-959-559
Phone Num : 2004959559
</pre>
<h2>Regular Expression Modifiers: Option Flags</h2>
<p>Regular expression literals may include an optional modifier to control various aspects of matching. The modifiers are specified as an optional flag. You can provide multiple modifiers using exclusive OR (|), as shown previously and may be represented by one of these −</p>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Modifier & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>re.I</b></p>
<p>Performs case-insensitive matching.</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>re.L</b></p>
<p>Interprets words according to the current locale. This interpretation affects the alphabetic group (\w and \W), as well as word boundary behavior(\b and \B).</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td><p><b>re.M</b></p>
<p>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).</p></td>
</tr>
<tr>
<td class="ts">4</td>
<td><p><b>re.S</b></p>
<p>Makes a period (dot) match any character, including a newline.</p></td>
</tr>
<tr>
<td class="ts">5</td>
<td><p><b>re.U</b></p>
<p>Interprets letters according to the Unicode character set. This flag affects the behavior of \w, \W, \b, \B.</p></td>
</tr>
<tr>
<td class="ts">6</td>
<td><p><b>re.X</b></p>
<p>Permits "cuter" regular expression syntax. It ignores whitespace (except inside a set [] or when escaped by a backslash) and treats unescaped # as a comment marker.</p></td>
</tr>
</table>
<h2>Regular Expression Patterns</h2>
<p>Except for control characters, <b>(+ ? . * ^ $ ( ) [ ] { } | \)</b>, all characters match themselves. You can escape a control character by preceding it with a backslash.</p>
<p>Following table lists the regular expression syntax that is available in Python −</p>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Pattern & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>^</b></p>
<p>Matches beginning of line.</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>$</b></p>
<p>Matches end of line.</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td><p><b>.</b></p>
<p>Matches any single character except newline. Using m option allows it to match newline as well.</p></td>
</tr>
<tr>
<td class="ts">4</td>
<td><p><b>[...]</b></p>
<p>Matches any single character in brackets.</p></td>
</tr>
<tr>
<td class="ts">5</td>
<td><p><b>[^...]</b></p>
<p>Matches any single character not in brackets</p></td>
</tr>
<tr>
<td class="ts">6</td>
<td><p><b>re*</b></p>
<p>Matches 0 or more occurrences of preceding expression.</p></td>
</tr>
<tr>
<td class="ts">7</td>
<td><p><b>re+</b></p>
<p>Matches 1 or more occurrence of preceding expression.</p></td>
</tr>
<tr>
<td class="ts">8</td>
<td><p><b>re?</b></p>
<p>Matches 0 or 1 occurrence of preceding expression.</p></td>
</tr>
<tr>
<td class="ts">9</td>
<td><p><b>re{ n}</b></p>
<p>Matches exactly n number of occurrences of preceding expression.</p></td>
</tr>
<tr>
<td class="ts">10</td>
<td><p><b>re{ n,}</b></p>
<p>Matches n or more occurrences of preceding expression.</p></td>
</tr>
<tr>
<td class="ts">11</td>
<td><p><b>re{ n, m}</b></p>
<p>Matches at least n and at most m occurrences of preceding expression.</p></td>
</tr>
<tr>
<td class="ts">12</td>
<td><p><b>a| b</b></p>
<p>Matches either a or b.</p></td>
</tr>
<tr>
<td class="ts">13</td>
<td><p><b>(re)</b></p>
<p>Groups regular expressions and remembers matched text.</p></td>
</tr>
<tr>
<td class="ts">14</td>
<td><p><b>(?imx)</b></p>
<p>Temporarily toggles on i, m, or x options within a regular expression. If in parentheses, only that area is affected.</p></td>
</tr>
<tr>
<td class="ts">15</td>
<td><p><b>(?-imx)</b></p>
<p>Temporarily toggles off i, m, or x options within a regular expression. If in parentheses, only that area is affected.</p></td>
</tr>
<tr>
<td class="ts">16</td>
<td><p><b>(?: re)</b></p>
<p>Groups regular expressions without remembering matched text.</p></td>
</tr>
<tr>
<td class="ts">17</td>
<td><p><b>(?imx: re)</b></p>
<p>Temporarily toggles on i, m, or x options within parentheses.</p></td>
</tr>
<tr>
<td class="ts">18</td>
<td><p><b>(?-imx: re)</b></p>
<p>Temporarily toggles off i, m, or x options within parentheses.</p></td>
</tr>
<tr>
<td class="ts">19</td>
<td><p><b>(?#...)</b></p>
<p>Comment.</p></td>
</tr>
<tr>
<td class="ts">20</td>
<td><p><b>(?= re)</b></p>
<p>Specifies position using a pattern. Doesn't have a range.</p></td>
</tr>
<tr>
<td class="ts">21</td>
<td><p><b>(?! re)</b></p>
<p>Specifies position using pattern negation. Doesn't have a range.</p></td>
</tr>
<tr>
<td class="ts">22</td>
<td><p><b>(?> re)</b></p>
<p>Matches independent pattern without backtracking.</p></td>
</tr>
<tr>
<td class="ts">23</td>
<td><p><b>\w</b></p>
<p>Matches word characters.</p></td>
</tr>
<tr>
<td class="ts">24</td>
<td><p><b>\W</b></p>
<p>Matches nonword characters.</p></td>
</tr>
<tr>
<td class="ts">25</td>
<td><p><b>\s</b></p>
<p>Matches whitespace. Equivalent to [\t\n\r\f].</p></td>
</tr>
<tr>
<td class="ts">26</td>
<td><p><b>\S</b></p>
<p>Matches nonwhitespace.</p></td>
</tr>
<tr>
<td class="ts">27</td>
<td><p><b>\d</b></p>
<p>Matches digits. Equivalent to [0-9].</p></td>
</tr>
<tr>
<td class="ts">28</td>
<td><p><b>\D</b></p>
<p>Matches nondigits.</p></td>
</tr>
<tr>
<td class="ts">29</td>
<td><p><b>\A</b></p>
<p>Matches beginning of string.</p></td>
</tr>
<tr>
<td class="ts">30</td>
<td><p><b>\Z</b></p>
<p>Matches end of string. If a newline exists, it matches just before newline.</p></td>
</tr>
<tr>
<td class="ts">31</td>
<td><p><b>\z</b></p>
<p>Matches end of string.</p></td>
</tr>
<tr>
<td class="ts">32</td>
<td><p><b>\G</b></p>
<p>Matches point where last match finished.</p></td>
</tr>
<tr>
<td class="ts">33</td>
<td><p><b>\b</b></p>
<p>Matches word boundaries when outside brackets. Matches backspace (0x08) when inside brackets.</p></td>
</tr>
<tr>
<td class="ts">34</td>
<td><p><b>\B</b></p>
<p>Matches nonword boundaries.</p></td>
</tr>
<tr>
<td class="ts">35</td>
<td><p><b>\n, \t, etc.</b></p>
<p>Matches newlines, carriage returns, tabs, etc.</p></td>
</tr>
<tr>
<td class="ts">36</td>
<td><p><b>\1...\9</b></p>
<p>Matches nth grouped subexpression.</p></td>
</tr>
<tr>
<td class="ts">37</td>
<td><p><b>\10</b></p>
<p>Matches nth grouped subexpression if it matched already. Otherwise refers to the octal representation of a character code.</p></td>
</tr>
</table>
<h2>Regular Expression Examples</h2>
<h3>Literal characters</h3>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Example & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>python</b></p>
<p>Match "python".</p></td>
</tr>
</table>
<h2>Character classes</h2>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Example & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>[Pp]ython</b></p>
<p>Match "Python" or "python"</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>rub[ye]</b></p>
<p>Match "ruby" or "rube"</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td><p><b>[aeiou]</b></p>
<p>Match any one lowercase vowel</p></td>
</tr>
<tr>
<td class="ts">4</td>
<td><p><b>[0-9]</b></p>
<p>Match any digit; same as [0123456789]</p></td>
</tr>
<tr>
<td class="ts">5</td>
<td><p><b>[a-z]</b></p>
<p>Match any lowercase ASCII letter</p></td>
</tr>
<tr>
<td class="ts">6</td>
<td><p><b>[A-Z]</b></p>
<p>Match any uppercase ASCII letter</p></td>
</tr>
<tr>
<td class="ts">7</td>
<td><p><b>[a-zA-Z0-9]</b></p>
<p>Match any of the above</p></td>
</tr>
<tr>
<td class="ts">8</td>
<td><p><b>[^aeiou]</b></p>
<p>Match anything other than a lowercase vowel</p></td>
</tr>
<tr>
<td class="ts">9</td>
<td><p><b>[^0-9]</b></p>
<p>Match anything other than a digit</p></td>
</tr>
</table>
<h2>Special Character Classes</h2>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Example & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>.</b></p>
<p>Match any character except newline</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>\d</b></p>
<p>Match a digit: [0-9]</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td><p><b>\D</b></p>
<p>Match a nondigit: [^0-9]</p></td>
</tr>
<tr>
<td class="ts">4</td>
<td><p><b>\s</b></p>
<p>Match a whitespace character: [ \t\r\n\f]</p></td>
</tr>
<tr>
<td class="ts">5</td>
<td><p><b>\S</b></p>
<p>Match nonwhitespace: [^ \t\r\n\f]</p></td>
</tr>
<tr>
<td class="ts">6</td>
<td><p><b>\w</b></p>
<p>Match a single word character: [A-Za-z0-9_]</p></td>
</tr>
<tr>
<td class="ts">7</td>
<td><p><b>\W</b></p>
<p>Match a nonword character: [^A-Za-z0-9_]</p></td>
</tr>
</table>
<h2>Repetition Cases</h2>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Example & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>ruby?</b></p>
<p>Match "rub" or "ruby": the y is optional</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>ruby*</b></p>
<p>Match "rub" plus 0 or more ys</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td><p><b>ruby+</b></p>
<p>Match "rub" plus 1 or more ys</p></td>
</tr>
<tr>
<td class="ts">4</td>
<td><p><b>\d{3}</b></p>
<p>Match exactly 3 digits</p></td>
</tr>
<tr>
<td class="ts">5</td>
<td><p><b>\d{3,}</b></p>
<p>Match 3 or more digits</p></td>
</tr>
<tr>
<td class="ts">6</td>
<td><p><b>\d{3,5}</b></p>
<p>Match 3, 4, or 5 digits</p></td>
</tr>
</table>
<h2>Nongreedy repetition</h2>
<p>This matches the smallest number of repetitions −</p>
<table class="table table-bordered">
<tr>
<th style="text-align:center;">Sr.No.</th>
<th style="text-align:center;">Example & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b><.*></b></p>
<p>Greedy repetition: matches "<python>perl>"</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b><.*?></b></p>
<p>Nongreedy: matches "<python>" in "<python>perl>"</p></td>
</tr>
</table>
<h2>Grouping with Parentheses</h2>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Example & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>\D\d+</b></p>
<p>No group: + repeats \d</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>(\D\d)+</b></p>
<p>Grouped: + repeats \D\d pair</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td><p><b>([Pp]ython(, )?)+</b></p>
<p>Match "Python", "Python, python, python", etc.</p></td>
</tr>
</table>
<h2>Backreferences</h2>
<p>This matches a previously matched group again −</p>
<table class="table table-bordered">
<tr>
<th style="text-align:center;">Sr.No.</th>
<th style="text-align:center;">Example & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>([Pp])ython&\1ails</b></p>
<p>Match python&pails or Python&Pails</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>(['"])[^\1]*\1</b></p>
<p>Single or double-quoted string. \1 matches whatever the 1st group matched. \2 matches whatever the 2nd group matched, etc.</p></td>
</tr>
</table>
<h2>Alternatives</h2>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Example & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>python|perl</b></p>
<p>Match "python" or "perl"</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>rub(y|le))</b></p>
<p>Match "ruby" or "ruble"</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td><p><b>Python(!+|\?)</b></p>
<p>"Python" followed by one or more ! or one ?</p></td>
</tr>
</table>
<h2>Anchors</h2>
<p>This needs to specify match position.</p>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Example & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>^Python</b></p>
<p>Match "Python" at the start of a string or internal line</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>Python$</b></p>
<p>Match "Python" at the end of a string or line</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td><p><b>\APython</b></p>
<p>Match "Python" at the start of a string</p></td>
</tr>
<tr>
<td class="ts">4</td>
<td><p><b>Python\Z</b></p>
<p>Match "Python" at the end of a string</p></td>
</tr>
<tr>
<td class="ts">5</td>
<td><p><b>\bPython\b</b></p>
<p>Match "Python" at a word boundary</p></td>
</tr>
<tr>
<td class="ts">6</td>
<td><p><b>\brub\B</b></p>
<p>\B is nonword boundary: match "rub" in "rube" and "ruby" but not alone</p></td>
</tr>
<tr>
<td class="ts">7</td>
<td><p><b>Python(?=!)</b></p>
<p>Match "Python", if followed by an exclamation point.</p></td>
</tr>
<tr>
<td class="ts">8</td>
<td><p><b>Python(?!!)</b></p>
<p>Match "Python", if not followed by an exclamation point.</p></td>
</tr>
</table>
<h2>Special Syntax with Parentheses</h2>
<table class="table table-bordered">
<tr>
<th style="text-align:center;width:10%">Sr.No.</th>
<th style="text-align:center;">Example & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td><p><b>R(?#comment)</b></p>
<p>Matches "R". All the rest is a comment</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td><p><b>R(?i)uby</b></p>
<p>Case-insensitive while matching "uby"</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td><p><b>R(?i:uby)</b></p>
<p>Same as above</p></td>
</tr>
<tr>
<td class="ts">4</td>
<td><p><b>rub(?:y|le))</b></p>
<p>Group only without creating \1 backreference</p></td>
</tr>
</table>
<div class="mui-container-fluid button-borders show" id="bottom_navigation">
<div class="pre-btn">
<a href="/python/python_classes_objects.htm"><i class="fal fa-chevron-circle-left"></i> Previous Page</a>
<a class="hide-on-mobile" href="javascript:printPage();"><i class="fa fa-print"></i> Print Page</a>
</div>
<div class="nxt-btn">
<a href="/python/python_cgi_programming.htm">Next Page <i class="fal fa-chevron-circle-right"></i> </a>
</div>
</div>
<div class="space-bottom" style="margin-bottom:20px;"></div>
<div class="google-bottom-ads" id="google-bottom-ads">
<div>Advertisements</div>
<div>
<div id="adp_bottom_ads"></div>
<script>
var adPos = document.getElementById('adp_bottom_ads');
var mobile_ad_id = "a8a632a6-046e-4f5c-b25f-8bc82ac89fb2";
var desktop_ad_id = "e7ddd6f7-1ab0-494a-bade-887daa4373a0";
var adpushup = adpushup || {};
adpushup.que = adpushup.que || [];
adpushup.que.push(function() {
var ad_id = window.innerWidth <= 768 ? mobile_ad_id : desktop_ad_id;
adPos.innerHTML = '<div id="' + ad_id + '" class="_ap_apex_ad"></div>';
adpushup.triggerAd(ad_id);
});
</script>
</div>
<div class="space-bottom"></div>
</div>
</div>
<!-- Tutorial Content Ends Here -->
<!-- Right Column Starts Here -->
<div class="mui-col-md-2 google-right-ads" id="chapter-menu" style="display: none;">
<input type="hidden" id="vu" name="vu" value=""/>
<div class="space-top"></div>
<div class="mui-panel">
<ul class="paid-menu" id="div-right-menu">
<li><a class="hide-on-mobile" href="javascript:printPage();" title="Print this page"><i class="fa fa-print"></i> Print</a></li>
<li><a href="javascript:void(0)" class="add_notes" title="Add Custom Notes" onclick="add_notes();"><i class="fa fa-edit"></i> Add Notes</a></li>
<li><a href="javascript:void(0)" class="clsPage text-bookmark" id="text-bookmark" title="Add Bookmark" onclick="text_bookmark()"><i class="fal fa-bookmark"></i> Bookmark this page </a></li>
<li><a href="javascript:void(0);" id="report_error_popup" onclick="report_error_popup();" title="Report Error"><i class="fal fa-bell"></i> Report Error</a></li>
<li><a href="javascript:void(0);" id="suggestion_popup" title="Give Suggestions" onclick="suggestion_popup();"><i class="fal fa-badge-check"></i> Suggestions</a></li>
</ul>
<div class="profile-my-notes" id="text_notes_div" style="display:none;">
<textarea rows="10" class="text_notes" id="text_notes" name="text_notes" placeholder="Enter your custom notes..."></textarea>
<br>
<a href="javascript:void(0);" id="submit_text_notes" class="butn-save" onclick="submit_text_notes();"> Save</a>
<a href="javascript:void(0);" class="pop-no butn-cancel" onclick="notesClose();"> Close</a>
<p class="notes_msg" ></p>
</div>
<div class="bottom-menu">
<button class="tp-btn"><i class="fal fa-box-up"></i> <a href="/videotutorials/dashboard.php">Dashboard</a></button>
<button class="tp-btn"><i class="fal fa-sign-out-alt"></i> <a href="/videotutorials/userlogout.php">Logout</a></button>
</div>
</div>
</div>
<div class="mui-col-md-2 google-right-ads" id="google-right-ads">
<div class="space-top"></div>
<div class="google-right-ad" style="margin: 0px auto !important;margin-top:5px;min-height:250px!important">
<div id="f0f6cff6-393d-4170-b63a-d9ff06ca9f25" class="_ap_apex_ad">
<script>
var adpushup = adpushup || {};
adpushup.que = adpushup.que || [];
adpushup.que.push(function() {
adpushup.triggerAd("f0f6cff6-393d-4170-b63a-d9ff06ca9f25");
});
</script>
</div>
</div>
<div class="google-right-ad" style="margin-top:16px;min-height:250px!important">
<div id="5c0affd5-724a-475c-bfcd-cecbc7660c36" class="_ap_apex_ad">
<script>
var adpushup = adpushup || {};
adpushup.que = adpushup.que || [];
adpushup.que.push(function() {
adpushup.triggerAd("5c0affd5-724a-475c-bfcd-cecbc7660c36");
});
</script>
</div>
</div>
<div class="google-right-ad" style="margin-top:16px;margin-bottom:15px;min-height:600px!important">
<div id="8f8814c2-d64c-4d26-9cb9-543653c0b48f" class="_ap_apex_ad">
<script>
var adpushup = adpushup || {};
adpushup.que = adpushup.que || [];
adpushup.que.push(function() {
adpushup.triggerAd("8f8814c2-d64c-4d26-9cb9-543653c0b48f");
});
</script>
</div>
</div>
<div class="space-bottom" style="margin-bottom:15px;"></div>
</div>
<!-- Right Column Ends Here -->
</div>
</div>
<div class="clear"></div>
<footer id="footer">
<div class="mui--text-center">
<div class="mui--text-caption mui--text-light">
<a href="/index.htm" class="logo"><img class="img-responsive" src="/images/logo-black.png" alt="Tutorials Point" title="Tutorials Point"></a>
</div>
<ul class="mui-list--inline mui--text-body2 mui--text-light">
<li><a href="/about/index.htm"><i class="fal fa-globe"></i> About us</a></li>
<li><a href="/about/return_refund_policy.htm"> <i class="fal fa-asterisk"></i> Refund Policy</a></li>
<li><a href="/about/about_terms_of_use.htm"><i class="fal fa-asterisk"></i> Terms of use</a></li>
<li><a href="/about/about_privacy.htm"> <i class="fal fa-shield-check"></i> Privacy Policy</a></li>
<li><a href="/about/faq.htm"><i class="fal fa-question-circle"></i> FAQ's</a></li>
<li><a href="/about/contact_us.htm"><i class="fal fa-map-marker-alt"></i> Contact</a></li>
</ul>
<div class="mui--text-caption mui--text-light bottom-copyright-text">© Copyright 2021. All Rights Reserved.</div>
</div>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-232293-6"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-232293-6');
</script>
<script src="/themes/js/jquery.colorbox-min.js"></script>
<script>
var tryit = new $.TryIt('/python/try_python.php');
tryit.compile();
</script><script src="https://www.tutorialspoint.com/videotutorials/js/text_menu.js?v=1"></script>
<script>
$(document).ready(function (){
var cval = readCookie('subscription_purchased');
if(cval == '1'){
// logged in and purchased subscription.
$('#google-right-ads').remove();
$('#adp1').remove();
$('#adp2').remove();
$('#stickyparent').remove();
$('#google-top-ads').remove();
$('#adp_top_ads').remove();
$('#google-bottom-ads').remove();
$('.tutorial-content hr').remove();
$('.login').remove();
$('#chapter-menu').show();
$('.content h1').css("border-bottom", "none");
$('.google-right-ads').css("padding-right", "0px");
$('.tutorial-content').css("border-radius", "10px");
$('#chapter-menu .mui-panel').css("border-radius", "10px");
}
});
</script>
</footer>
</body>
</html>