title: Testing regex with Java
body: <p>I'm learning regex and I'm using the following code snippet for testing purpose:</p>
  
  <pre><code>String regex = "";
  String test = "";
  Pattern.compile(regex).matcher(test).find();
  </code></pre>
  
  <p>but when I try some like this:</p>
  
  <pre><code>System.out.println(Pattern.compile("h{2,4}").matcher("hhhhh").find()); 
  </code></pre>
  
  <p>it returns true and not false as expected.</p>
  
  <p>or</p>
  
  <pre><code>System.out.println(Pattern.compile("h{2}").matcher("hhh").find());
  </code></pre>
  
  <p>it returns true and not false as expected.</p>
  
  <p>What's the problem? Maybe this is not the right statements to use for testing correctly the regex?</p>
  
  <p>thanks.</p>