title: n-digit Pattern Matching in Lua
body: <p>I'm new to Lua. </p>
  
  <p>Say i have a string "1234567890".</p>
  
  <p>I want to iterate over all possible 3 digit numbers. (ie <code>123,234,345,456....</code>)</p>
  
  <pre><code>for m in string.gmatch("1234567890","%d%d%d") do
        print (m)
  end
  </code></pre>
  
  <p>But this gives me the output <code>123,456,789</code>.</p>
  
  <p>What kind of Pattern should i be using? </p>
  
  <p>And secondly, a related question, how do i specify a <code>3-digit</code> number? <code>"%3d"</code> doesn't seem to work. Is <code>"%d%d%d"</code> the only way?</p>
  
  <p><em>Note:</em> This isn't tagged <code>Regular expression</code>because Lua doesn't have RegExp. (atleast natively)</p>
  
  <p>Thanks in advance :)</p>
  
  <p><strong>Update:</strong> As Amber Points out, there is no "overlapping" matches in Lua. And, about the second query, i'm now stuck using <code>string.rep("%d",n)</code> since Lua doesn't support fixed number of repeats.</p>