def compare(s1: str, s2: str) -> bool:
if s1 == s2:
return True
if '*' in s2 and len(s1)>=len(s2):
li = s2.split('*')
if s1.startswith(li[0]) and s1.endswith(li[1]):
return True
else:
return False
else:
return False
def compare(s1:str,s2:str):
len1=len(s1)
len2=len(s2)
if len1<len2:
return False
if '*' not in s2:
if s1==s2:
return True
else:
return False
else:
index=s2.find('*')
if index==0:
if s2[1:]==s1[(len1-len2+1):]:
return True
else:
return False
elif index==len2-1:
if s2[:-1]==s1[:(-(1+len2-len1))]:
return True
else:
return False
else:
if s2[0:index]==s1[0:index] and s2[index+1:]==s1[(len1-len2+1+index):]:
return True
else:
return False
def compare(s1: str, s2: str) -> bool:
l = len(s1) - len(s2)
new_list1 = list(s1)
new_list2 = list(s2)
if l < 0:
return False
else:
for i in range(len(new_list2)):
if new_list2[i] == '*':
new_list2.remove('*')
for j in range(l+1):
new_list2.insert(i+j, new_list1[i])
return new_list1 == new_list2
assert compare("abccd", "abccd") is True
assert compare("abccd", "abcd") is False
assert compare("abccd", "ab*d") is True
assert compare("abccd", "ab*cy") is False
assert compare("abccd", "abccd") is True
assert compare("abccd", "abcd") is False
assert compare("abccd", "ab*d") is True
assert compare("ccdab", "ab*d") is False
assert compare("abccd", "ab*cy") is False
assert compare("abccd", "*") is True
assert compare("abccd", "a*") is True
assert compare("abccd", "c*") is False
assert compare("abccd", "*d") is True
assert compare("abccd", "*c") is False
assert compare("abc", "ab*c") is False
def compare2(s1: str, s2: str) -> bool:
s2_list = s2.split('*')
last_index = 0
for i in range(len(s2_list)):
if last_index >= len(s1): return False
if i == 0 :
if not s1.startswith(s2_list[i]): return False
elif i == len(s2_list)-1:
if not s1.endswith(s2_list[i]): return False
else:
new_index = s1.find(s2_list[i],last_index)
if new_index < last_index: return False
last_index += len(s2_list[i])+1
return True
assert compare("abccd", "abccd") is True
assert compare("abccd", "abcd") is False
assert compare("abccd", "ab*d") is True
assert compare("ccdab", "ab*d") is False
assert compare("abccd", "ab*cy") is False
assert compare("abccd", "*") is True
assert compare("abccd", "a*") is True
assert compare("abccd", "c*") is False
assert compare("abccd", "*d") is True
assert compare("abccd", "*c") is False
assert compare("abc", "ab*c") is False
assert compare("abccd", "**") is True
assert compare("abccdjalsdjf", "*c*") is True
assert compare("abccdjalsdjf", "a*c*") is True
assert compare("abccdjalsdjf", "a*c*f") is True
assert compare("abccdjalsdjf", "*c*f") is True
assert compare("abccdjalsdjf", "a*d*z*f") is False
assert compare("abccdjalsdjf", "c*y*d") is False
import re
def compare(s1: str, s2: str) -> bool:
match_obj = re.match(s2.replace('*','.+'),s1)
return s1 == match_obj.group() if bool(match_obj) else False