I found on the internet this regex in javascript that formats monetary values in R $:
Number( 1450999 )
.toFixed( 2 )
.replace( '.', ',' )
.replace( /(\d)(?=(\d{3})+,)/g, "$1," )
// 1450999 -> 1.450.999,00
I have been analyzing for a long time and I still do not understand how this regex works. For example, in the case regex does a global search, but if I remove this parameter, the return is a match to the digit 1:
Number( 1450999 )
.toFixed( 2 )
.replace( '.', ',' )
.replace( /(\d)(?=(\d{3})+,)/, "$1." )
// 1450999 -> 1.450999,00
The question is as follows, how can this regex take the digit 1 as a match if it is not followed by 3 digits and a comma, just as it sends the regex. Would not you have to get the digit 0?