The string we are replacing with, 'ident', is interpreted as a regex by itself.

The part '([^0-9])' is a capture group in the search pattern, that looks ahead one character that is not a digit. We must add it back to the string we are substituting, or that lookahead character would be erased in the replace. The $1 refers to this. The '$' -> '$$$$' is doubling up a '$' sign in the string 'ident', to escape it so that the actual '$' character is not treated as a regex special character, but a part of the variable.

E.g. If ident = '$163', then ident.replace('$', '$$$$') + '$1' == '$$163$1', which as regex is interpreted as a string "$163" followed by whatever the first capture group matched, in this case, the '([^0-9])'.