This is what I am trying to do :
Given a string, 12345678, commify(str) should give me 12,345,678.
The problem is to be solved using regex with Perl, and the solution that works for this problem is this :
s/(?<=\d)(?=(\d\d\d)+(?!\d))/,/g
Source : Mastering Regular Expressions
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 ?
Note : I have found similar questions but they don't seem to explain how the problem is solved but rather state the exact answer.