Question: I am trying to implement wild cards in Java.

Here is the code I have :

```
public class Assign {

public boolean compare(String s1, String s2)
{
    char [] s3 = s1.toCharArray();
    char [] s4 = s2.toCharArray();
    int i,j;

    int k = 0;
    for(i=0;i<s3.length;i++)
    {
        for(j=0;j<s4.length;j++)
        {
            if(s3[i] == s4[j])
            {

                if(s4[j] == '*')
                {
                    i++;

                    if(s3[i] == s4[s4.length-1])
                    {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
public static void main(String args[])
{
    Assign a = new Assign();
    boolean r = a.compare("a hello b", "a * b");
    System.out.println(r);
}
}

```

There will be two parameters to be passed to the function. One is a string and the other one is a regular expression.

**Example cases are:**

1) If string passed is "a hello b" and the regular expression is "a \* b" then the function should return TRUE because in the place of \* any number of characters can exist.

2) If string passed is "a X b" and the regular expression is "a ? b" then the return value should be TRUE because if there is a ? in regular expression then there should be only one character between a and b.

Like this it shall work for all cases. I think the logic I thought is fine but I ma having a trouble in the coding part.

I dont want to import Pattern and Matcher. Without them I have to complete this.

Kindly, anyone help me on this by specifying the correct code.

Thanking you

Answer: 
Use regular expressions. Don't reinvent the wheel.
As i said, you can do this extracting simple sub string's.Here I checked
for one case, do same thing for other cases.

```
     public class Assign {

public boolean compare(String s1, String s2)
{ String s="";
    try
    {
 s=s1.substring(s1.indexOf('a')+2,s1.indexOf('b')-1);
    }
    catch(IndexOutOfBoundsException e)
    {
    return false;
    }
    System.out.println("string: "+s);

    if(s2.substring(2,3).equals("*")&&s.length()>=1)
    {return true;}
    else
        return false;

}
public static void main(String args[])
{
    Assign a = new Assign();
    boolean r = a.compare("a b hello", "a * b");
    System.out.println(r);
}
}

```

**EDIT :**
May be i have not checked for all the cases.It's a way to approach.