Python program to check if two strings match where one string contains wildcard characters
Login/Signup to comment
2 comments on “Python program to check if two strings match where one string contains wildcard characters”
×


30+ Companies are Hiring
Get Hiring Updates right in your inbox from PrepInsta
public class S23_two_match_or_not
{
public static void main(String args[])
{
String s1=”Prepins*a”;
String s2=”Prepinsta”;
check(s1, s2);
}
public static void check(String s1,String s2)
{
StringBuilder a1=new StringBuilder(s1);
StringBuilder a2=new StringBuilder(s2);
for(int i=0;i=’a’ && a1.charAt(i)=’A’ && a1.charAt(i)<='Z'))
{
a1.deleteCharAt(i);
i–;
}
}
for(int i=0;i=’a’ && a2.charAt(i)=’A’ && a2.charAt(i)<='Z'))
{
a2.deleteCharAt(i);
i–;
}
}
System.out.println(a1);
System.out.println(a2);
int flag=0;
for(int i=0;i<a1.length();i++)
{
if(a1.charAt(i)!=a2.charAt(i))
{
System.out.println("false");
return;
}
}
System.out.println("true");
}
}
str1 = str(input(“Enter the string with wild charaters: “))
str2 = str(input(“Enter the string without wild characters: “))
string = “*”
index1 = str1.index(“*”)
index2 = len(str1) – str1[::-1].index(“*”) – 1
for string in str1:
str1 = str1.replace(“*”,””)
str2 = str2[:index1]+str2[index2+1:]
len1 = len(str1)
len2 = len(str2)
if str1 == str2 and len1 == len2:
print(True)
else:
print(False)