ADVERTISEMENT
ADVERTISEMENT

Python program to search for regular expression in string using search() method

Here, we will see a Python program to search for regular expressions in string using search() method using search method.
Submitted by Shivang Yadav, on March 10, 2021

The regular expression in Python is a search pattern formed by a sequence of characters.

The search() method is used to search for the occurrence of regex patterns in the string.

Syntax:

regex.match(regexPattern, string, flag)

Let's take an example to understand the problem,

Input:
string = "learn python programming language at includehelp" ; pattern = '(.*) at (.*?)'

Output:
Search Item Found

Program to illustrate the working of our solution

import re

myString = "learn python programming language at includehelp"

searchObject = re.search( r'(.*) python (.*?) .* ', myString, re.M|re.I)
if searchObject:
    print("Item found! ")
else:
    print("No Item are found!")

Output:

Item found!

Python Regular Expression Programs »



ADVERTISEMENT


ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

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

© https://www.includehelp.com some rights reserved.