title: Regular expressions (ab*foo) vs (a.*foo) difference?
body: <p>From this <a href="http://docs.oracle.com/javase/tutorial/essential/regex/quant.html" rel="nofollow">tutorial</a> I learned about "Regular Expressions - Quantifiers", and based on this <a href="http://docs.oracle.com/javase/tutorial/essential/regex/test_harness.html" rel="nofollow">test code</a> used in this tutorial.</p>
  
  <p>I have a question on these tests:</p>
  
  <pre><code>Enter your regex: ab*foo
  Enter input string to search: xabfooxxxabbbfoox
  I found the text "abfoo" starting at index 1 and ending at index 6.
  I found the text "abbbfoo" starting at index 9 and ending at index 16.
  </code></pre>
  
  <p>But</p>
  
  <pre><code>Enter your regex: a.*foo
  Enter input string to search: xabfooxxxabbbfoox
  I found the text "abfooxxxabbbfoo" starting at index 1 and ending at index 16.
  </code></pre>
  
  <p>Why Not these:</p>
  
  <pre><code>I found the text "abfoo" starting at index 1 and ending at index 6.
  I found the text "abbbfoo" starting at index 9 and ending at index 16.
  </code></pre>
  
  <p>In general I noteiced that whenever <code>.*</code> or <code>.+</code> used:</p>
  
  <ul>
  <li><p>There is only a single match if any.</p></li>
  <li><p>The matched section of the string is always the longest one.</p></li>
  </ul>
  
  <p>So how Matching work for each?</p>