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,

key = "includehelp" ; expression = "learn programming at includehelp"


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)


Expression :  this is a sample regular expression data
Is [sample] present in expression :  True

Python Regular Expression Programs »

Comments and Discussions

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.