Home »
Python »
Python programs
Python program to check the presence of substring in given string - Regex Example
Here, we will see a Python program to check the presence of a substring in a given string.
Submitted by Shivang Yadav, on March 10, 2021
Python programming language supports regular expression. RegEx is a sequence of characters for matching with other strings.
Here, we are given an expression and key. And we have a program to check whether the key is present in the expression.
Let's take an example to illustrate the working of our solution,
Input:
key = "includehelp" ; expression = "learn programming at includehelp"
Output:
True
We will use the in method which checks for the presence of a substring in the string and returns a boolean value based on the comparison.
Python code:
expression = "this is a sample regular expression data"
print("Expression : ",expression)
key = "sample"
print("Is [sample] present in expression : ",key in expression)
Output:
Expression : this is a sample regular expression data
Is [sample] present in expression : True
Python Regular Expression Programs »