Table of Contents
Introduction
In this article our task is to search whether the given input string contains specific characters.
Program
import re def verify(ip_str, re_exp): if re.search(re_exp, ip_str): print("{0} is present in the expression {1}".format(ip_str, re_exp)) else: print("{0} is not present in the expression {1}".format(ip_str, re_exp)) re_exp = re.compile('[1234567]+!$' ) ip_str = input("Enter teh string to check: ") verify(ip_str, re_exp)
Output
Explanation
In the above code we have used compile() function and search() function of the regression module. Using compile() we complied the expression into pattern object. And to search the input string in the pattern we have used search().
0 Comments