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

Decorators In Python
A decorator takes in a function, adds some functionality and returns it. Functions and methods are called callable as they can be called. Any object which implements the special method __call__() is...

Big Data & Hadoop - Introductory Session - Data Science for Everyone
Data Science for Everyone An introductory video lesson on Big Data, the need, necessity, evolution and contributing factors. This is presented by Skill Sigma as part of the "Data Science for Everyone" series.

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

A program to determine the molecular weight of a hydrocarbon based on the number of Hydrogen,Carbon and Oxygen atoms.
import osimport math# A program to calculate Molecular Weight of a Hydrocarbon # These are the atomic weights(grams/mole) of Hydrogen,Carbon and OxygenatomicwtH = 1.0079atomicwtC = 12.011atomicwtO = 15.994Hatoms...

Two lists using Loops - Python Program 1
To generate a list of all possible combinations of two lists using loops, you can use nested loops to iterate through both lists and create a new list that contains all the combinations. list1 = list2...
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