title: Matching 3-digit-groups in a string using regular expressions
body: <p>This is what I am trying to do : </p>
  
  <blockquote>
    <p>Given a string, 12345678, commify(str) should give me 12,345,678.</p>
  </blockquote>
  
  <p>The problem is to be solved using regex with Perl, and the solution that works for this problem is this : </p>
  
  <blockquote>
    <p>s/(?&lt;=\d)(?=(\d\d\d)+(?!\d))/,/g</p>
  </blockquote>
  
  <p><strong>Source</strong> : Mastering Regular Expressions </p>
  
  <p>The problem I am having in understanding this is how we are able to capture the "345" part of this string. One thing that I could think about is that the regex pointer "i" ( this is how I am visualising it ) starts at 1, another pointer "j" traverses the entire string and finds the appropriate location between 5 and 6. Then i moves to 2. "j" traverses the entire string again, finds the appropriate position between 2 and 3(since now a comma has been inserted between 5 and 6).
  Is my understanding correct ? If not, could anybody help me to visualise this process ?</p>
  
  <p>Note : I have found similar questions but they don't seem to explain how the problem is solved but rather state the exact answer.  </p>