findall() function in python by R4R Team

- findall() is a regular expresion function in python, that match the given pattern to the string and return the match pattern in the form of the list.

Syntax-

re.findall(pattern,string)

Example-

String is s="this is this buddy"
then re.findall("this",s) will return ["this","this"]


program-

#import the re module
import re

#take input of string and pattern for search
print("Enter string")
s=input()
print("Enter sunstring to be searched")
ss=input()

#fill all the match pattern in list
x=re.findall(ss,s)
print("After match :",x)
print("occurrence of match pattern :",len(x))


output-

Enter string
This is the island
Enter sunstring to be searched
is
After match : ['is', 'is', 'is']
occurrence of match pattern : 3


-In this program, we take a input of the string and the substring that we want to search, then findall() function find all the match pattern in the given string and return a list as shown in above output.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!