Regular Expression

Aditi Phalke
2 min readMay 11, 2021

A RegEx, or Regular Expression, is a sequence of characters that forms a search pattern. RegEx can be used to check if a string contains the specified search pattern.

Where did the term Regular Expressions come from?

The term regular expression comes from mathematics and computer science theory, where it reflects a trait of mathematical expressions called regularity. The text patterns used by the earliest grep tools were regular expressions in the mathematical sense. They are often called REs, or regexes, or regex patterns.

RegEx Module

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

Import the re module:

import re


Search the string to see if it starts with “The” and ends with “Spain”:

import re

txt = “The rain in Spain”
x =“^The.*Spain$”, txt)

if x:
print(“YES! We have a match!”)
print(“No match”)


YES! We have a match!


Thanks you. I hope this article is helpful for you.