Q:

How to escape the second capture group the first time in javascript regular expression

It would be helpful if someone could help me in suggesting a way to escape the second capture group the first time. The expression is as follows:
(\d)(?=(\d{3})(\d{2})+(?!\d))

I want the second capture group (\d{2}) to be skipped the first time and this group to be evaluated (\d{3}) just once.
The idea is to find position of a number. Right now, 1000000000 is being evaluated as  1,00,00,00000. I want it to be 1,00,00,00,000.

A:

It seems that this should work for you:
"1000000000".replace(/\d(?=(?:\d{2})*\d{3}(?!\d))/g, "$&,")

I dropped all the unnecessary capturing groups, and use $& to refer to the main match instead of capturing \d.

