Wild Card Search in Java
<p>I am trying to implement wild cards in Java.</p>

<p>Here is the code I have :</p>

<pre><code>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&lt;s3.length;i++)
    {
        for(j=0;j&lt;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);
}
}
</code></pre>

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

<p><strong>Example cases are:</strong></p>

<p>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.</p>

<p>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.</p>

<p>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.</p>

<p>I dont want to import Pattern and Matcher. Without them I have to complete this.</p>

<p>Kindly, anyone help me on this by specifying the correct code.</p>

<p>Thanking you</p>
