I just needed a solution to put points to separate numbers from three to three, backwards.
For example:
1000 => 1.000
100000 => 100.000
10000000 => 1.000.000
In a response I found in Stackoverflow English , the last solution was to use this regular expression:
function separarDeTresEmTres(numero)
{
return String(numero).split(/(?=(?:...)*$)/ ).join('.');
}
console.log(separarDeTresEmTres(1000));
console.log(separarDeTresEmTres(1000000));
console.log(separarDeTresEmTres(10000000));
But I did not quite understand what the magic of /(?=(?:...)*$)/
was.
What is causing this regular expression to separate the numbers from three to three backwards? What is the explanation?
NOTE : I do not want answers explaining how to separate a number from three to three, even because the regular expression I'm using is already doing this. The question here is specifically about how each part of that regular expression works. I do not want to solve the problem without explaining what is happening.