Python Tutorial

What is Python RegEx, Module and Uses

What is Python RegEx?

A RegEx, or Regular Expression, is a character sequence that defines a search pattern. RegEx can be used to determine whether or not a string contains the specified search pattern.

RegEx Module in Python

Regular Expressions can be worked with using a built-in Python library called re.

Import the re module:

import re

Use of RegEx in Python

The RegEx in Python can be used once you have imported the re module.


import re

txt = "The rain in Spain"

x ="^The.*Spain$", txt)
Did you find this article helpful?