title: Non-greedy Regular Expression in Java
body: <p>I have next code:</p>
  
  <pre><code>public static void createTokens(){
      String test = "test is a word word word word big small";
      Matcher mtch = Pattern.compile("test is a (\\s*.+?\\s*) word (\\s*.+?\\s*)").matcher(test);
      while (mtch.find()){
          for (int i = 1; i &lt;= mtch.groupCount(); i++){
              System.out.println(mtch.group(i));
          }
      }
  }
  </code></pre>
  
  <p>And have next output:</p>
  
  <pre><code>word
  w
  </code></pre>
  
  <p>But in my opinion it must be:</p>
  
  <pre><code>word
  word
  </code></pre>
  
  <p>Somebody please explain me why so?</p>