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

Python Dictionary
Python dictionary is an unordered collection of items. While other compound datatypes have only value as an element, a dictionary has a key: value pair. Dictionaries are optimized to retrieve values when...

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...

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

Python in Unix
Python in Unix How to run command on unix Commands cannot be run directly on a unix server like we do in shell script. SYNTAX: system("Command") check_output("Command", shell=True) call("Command",...
R

Rishi B.

0 0
0

What is a generator?
A generator is a function that has one or more yield statements. Example: >>>def gen_demo(a): yield a a = a+10 yield a a = a+30 yield a >>>gen_a...
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