I am trying to find a way to match a pattern p in a string s in python.
s = 'abccba'
ss = 'facebookgooglemsmsgooglefacebook'
p = 'xyzzyx'
# s, p -> a, z # s and p can only be 'a' through 'z'
def match(s, p):
if s matches p:
return True
else:
return False
match(s, p) # return True
match(ss, p) # return True
I just tried:
import re
s = "abccba"
f = "facebookgooglemsmsgooglefacebook"
p = "xyzzyx"
def fmatch(s, p):
p = re.compile(p)
m = p.match(s)
if m:
return True
else:
return False
print fmatch(s, p)
print fmatch(f, p)
Both return false; they are supposed to be true.
if p in swork for you?TrueandFalse. Capitalization is important.