OneCompiler

string matching

125

def strmatch(a,b):
a=" "+a+" "
b=" "+b+" "
n=len(a)
m=len(b)
count=0
for i in range(n-m+1):
if(a[i:i+m]==b):
print("Pattern found at ",i)
count+=1
if count==0:
print("Pattern nout found")

a=input("Enter i/p string: ")
b=input("Enter pattern: ")
strmatch(a,b)