UrbanPro
true

Learn Python Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Back Reference In Python Regex

Logeswaran
07/09/2017 0 0

What if your interviewer asks about this?

We know Regex have some useful functions like:

  • match  (  Ex: re.match(pattern,dataSource)   )
  • search (  Ex: re.search(pattern,dataSource)   )
  • sub      (  Ex: re.sub(pattern,replaceStr,dataSource)   
  • findall  (  Ex: re.findall(pattern,dataSource)   )
Do we heard the term back reference in python?
Let me explain sample examples: how to check whether the given string follows the given pattern?
 
Sample program implementation:
import re                   #re - Python Library for regular-expression 
sampleString="aabab"
findObj=re.match('(.+)\\1(.+)\\1\\2',sampleString)
                                #Above \\1 and \\2 back referencing the respective group of pattern
print findObj.group()
 
Output: Matched object: aabab
0 Dislike
Follow 2

Please Enter a comment

Submit

Other Lessons for You

Identity operators
Identity operators Operation Syntax Function Identity a is b is_(a, b) Membership operators Operation Syntax Function Containment obj in seq contains(seq, obj)

Python (Concepts and Importance)
Python is a general-purpose, interpreted, object-oriented programming language. Python was created by "G. V. Rossum" in the Netherlands in 1990. Python has become a famous programming language widely used...

Python Programming
Python is a widely used general-purpose, high-level programming language. This is an Open Source Software and its source code is available with a license in which the Copyright holder provides the rights...

Simulation of a die-roll:Usage of random module
Task:Simulation of a simple die-rolling game,where we keep rolling a six-sided die until we have rolled a total of 20. To simulate a six-sided die roll, we need a way to generate a random integer between...

Python Demo
https://www.youtube.com/watch?v=8AEhpZ4lbOI
X

Looking for Python Training Classes?

The best tutors for Python Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Python Training with the Best Tutors

The best Tutors for Python Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more