"12345678901890".replace(/(\d)(? =(\d{3})+$)/g, '$1,')

Parse the process: (\d) matches to 1 (? = (\ d {3}) + $) matched to 234 567 890 189 0 0 at the end is not in conformity with the ((\ d {3}) + $) (\ d) match to 2 (? = (\ d {3}) + $) matching end to 345, 678, 901, 890, 890 in accordance with ((\ d {3}) + $)

(\d) matches to 3 (? = (\ d {3}) + $) matched to 456, 789, 018, 90 at the end of 90 is not in conformity with the ((\ d {3}) + $)

.

So it matches 12,345,678,901,890