I came answers (below) to try and understand how consecutive lookaheads work. My understanding seems to be contradictory and was hoping someone could help clarify.
The answer here suggests that all the lookaheads specified must be present for the first matched character (Why consecutive lookaheads do not always work answer by Sam Whan)
If I apply that to the solution in this answer: How to print a number with commas as thousands separators in JavaScript:
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
it means that it's looking for the a non-boundary character that is followed by a sequence of characters with length that is a multiple of 3 and at the same time followed by characters that are not digits.
e.g. 12345
Knowing that a comma should go after the 2 but it seems contradictory as 2
has 3 digits following it, satisfying the first lookahead but the second lookahead contradicts it as it's supposed to not be followed by any digits.
I'm sure I'm misunderstanding something. Any help is appreciated. Thanks!