You can do this like this for the same number repeated several times (as in the example line):
'GhT111r1y11rt'.replace(/(\d)\1+/g, function (m,g1) { return g1 * m.length;});
(\d)fix the first digit
\1+repeat the captured digit (from group 1)
source
share