Python RegEx | Python Regular Expressions

Python RegEx – A RegEx, or Regular Expression, is basically a sequence of characters that forms or leads to a specific search pattern. RegEx is used to check whether a string contains the specified search pattern or not. 

Python already has a built-in package called re, which is used to work with Regular Expressions.

Importing:

import re

The re module offers a set of functions listed below:

 

  1. Search – It returns a Match object if there is a match anywhere in the string.
  2. Split – It returns a list where the string has been split at each match.
  3. Sub – It replaces one or many matches with the string.
  4. findall – It returns a list containing all matches.
Tags: No tags

Add a Comment

Your email address will not be published. Required fields are marked *