searching for a pattern in java
<p>yes guys its a kind of homework...but your help will be appreciated..</p>

<p>sorry for the previous incomplete question..i am a newcomer so please don't mind...</p>

<p>I've a string, e.g., "how aare you a re yo u a r e you ar e" and the string with which I want to compare is "are".</p>

<p>Now the problem is to find the occurrence of "are" in such a way that if it appears as "aare" it is ignored since it becomes a different word altogether, if it appears as "you a re" it is accepted since 'you' will be considered as a different pattern and 'a re' as another, if it appears as " u a r e " it is rejected since it forms a 'specific pattern like space word space word... so u will also become a part of 'are' and hence it should be rejected' and if it appears as "you ar e" it is accepted and "you a r e " is also accepted.</p>

<ul>
<li>"aare" it is ignored</li>
<li>"you a re" it is accepted</li>
<li>" u a r e " it is rejected</li>
<li>"you ar e" it is accepted</li>
<li>"you a r e " is also accepted</li>
</ul>

<p>i tried the following code: </p>

<pre><code>public class testPattern1 {

    public static void main(String args[])
    {
        String a="How aare yoar u a r e yo ar e";
        String compare="are";


        int i,temp=0;
        for(i=0;i&lt;a.length();i++)
        {
            if (a.charAt(i)==compare.charAt(0))
            {
                temp=i;
                temp++;

                for(int d=temp;d&lt;a.length();)
                {
                    while(a.charAt(temp)==' ')
                    {
                        temp++;
                    }

                    if(a.charAt(temp)==compare.charAt(1))
                    {
                        temp++;
                    }
                    else
                    {
                        break;
                    }
                    while(a.charAt(temp)==' ')
                    {
                        temp++;
                    }
                    if(a.charAt(temp)==compare.charAt(2))
                    {
                        System.out.println("matched at"+temp);
                    }
                    else
                    {
                        System.out.println("not matched at"+temp);
                    }

                }

            }


        }

    }

}
</code></pre>

<p>hope you guys have now understood the question..</p>
