In Python I can do this:
import re
s = '123123123123'
re.sub(r"(?<=.)(?=(?:...)+$)", ",", s )
123,123,123,123
How to make the same in JavaScript?
In Python I can do this:
import re
s = '123123123123'
re.sub(r"(?<=.)(?=(?:...)+$)", ",", s )
123,123,123,123
How to make the same in JavaScript?
No Lookbehinds in JavaScript
The question is interesting because JS has no lookbehinds. But we can do it like this:
replaced = yourString.replace(/(?!^)(?=(?:...)+$)/g, ",");
Explanation
(?!^)
negative lookahead is the trick to replace your lookbehind. It asserts that what follows is not the beginning of the string. And at the beginning of the string, which is a zero-width position, that fails (think of it as 0+0=0)(?=(?:...)+$
matches a position that is followed by three characters x one or more times then the end of the string, ensuring the insertion of the comma in the right spot.