title: java pattern matches not working
body: <p>i want to get class name from a string .for example <code>public class hello extends jframe</code> .then i want to get <code>hello</code> as class name .but if String is <code>public class hello</code> and also i want to get <code>hello</code>.</p>
  
  <p>i write a regex and it's work fine . <a href="http://regexr.com/3bgmk" rel="nofollow noreferrer">see here online preview</a> .</p>
  
  <p>this is my regex</p>
  
  <pre><code>(public)*\s*class\s+(\S+)\s+
  </code></pre>
  
  <p>preview</p>
  
  <p><a href="https://i.stack.imgur.com/4kzMi.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4kzMi.jpg" alt="enter image description here"></a></p>
  
  <p>as you can see it works ..it capture class names . (red color -> group 2)</p>
  
  <p>but in java <code>m.matches()</code> returns false  because whole string doesn't match but a part .so according to  <a href="https://stackoverflow.com/a/2526985/2227526">this answer</a> , i used <code>hitEnd()</code> method but it doesn't work either ?? how can i capture class name when even string exactly doesn't match but partially </p>
  
  <pre><code>String cstring = "public class hello extends jframe ";
  Pattern classPattern = Pattern.compile("(public)*\\s*class\\s+(\\S+)\\s*");
  Matcher m = classPattern.matcher(cstring);
  m.matches();
  if (m.hitEnd()) {
      System.out.println("found");
      String className = m.group(2);
      System.out.println(className);
  }
  </code></pre>
  
  <p>output is nothing.</p>