Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

Python Regular Expression

 

In this lecture we will see that,

What is regular expression ?

What is match and search function ?

How to work with patterns in regular expression ?

 

A regular expression (regex or regexp for short) is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids. You are probably familiar with the wildcard notations such as *.txt to find all text files in a file manager.

 

Match Function

 

This function determines if the RE matches at the beginning of the string.

Syntax :

re.match(pattern,string)

 

pattern : This is the regular expression to be match.

string : This is a string which would be searched to match the pattern at the beginning of string.

 

Search Function

 

Scan through a string, looking for any location where this RE matches.

Syntax :

re.search(pattern,string)

 

Patterns

 

Except for control characters ,(+?.*^$()[]{}|\), all characters match themselves. You can escape a control character by preceding it with a backslash.

 

Pattern

Description

|

Alteration, or the “or” operator.

^

Matches at the beginning of lines.

$

Matches at the end of a line.

\A

Matches only at starting of string.

\Z

Matches only at ending of string.

\b

Word boundary. This is zero-width assertion that matches only at the beginning or the end of the word.

\w

Matches the word characters.

\W

Matches the non word characters.

\d

Matches digits.

\D

Matches non digits.

\s

Matches whitespaces.

\S

Matches non whitespaces.

\B

Another zero-width assertion, this is the opposite of \b, only matching when the current position is not at a word boundary.

re{n,m}

Matches at least n and at most m occurrences of preceding expression.

 

FAQs

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere