×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

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 »



Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.