You must remember that (?=...) is a zero-width
assertion. Thus (\d{3})(?=(\d{3})+)$
tries to first match three digits, then sees if the text
after where it is in the string matches (\d{3})+without moving further in the string and then sees it can match an end
of string or newline after its current location in the string.