title: How to use regular expression to use as few groups as possible to match as long string as possible
body: <p>For example, this is the regular expression</p>
  
  <pre><code>([a]{2,3})
  </code></pre>
  
  <p>This is the string</p>
  
  <pre><code>aaaa // 1 match "(aaa)a" but I want "(aa)(aa)"
  aaaaa // 2 match "(aaa)(aa)"
  aaaaaa // 2 match "(aaa)(aaa)"
  </code></pre>
  
  <p>However, if I change the regular expression</p>
  
  <pre><code>([a]{2,3}?)
  </code></pre>
  
  <p>Then the results are</p>
  
  <pre><code>aaaa // 2 match "(aa)(aa)"
  aaaaa // 2 match "(aa)(aa)a" but I want "(aaa)(aa)"
  aaaaaa // 3 match "(aa)(aa)(aa)" but I want "(aaa)(aaa)"
  </code></pre>
  
  <p>My question is that is it possible to use as few groups as possible to match as long string as possible?</p>