I'm running a regular replace tag to format a string, such as the CPF:
var cpf = '99999999999';
cpfFormatado = cpf.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, '$1.$2.$3-$+');
console.log(cpfFormatado); // 999.999.999-99
I'm trying to reduce the regular expression, however I can not find the correct way to use the groups in the replacement string:
var cpf = '99999999999';
cpfFormatado = cpf.replace(/(\d{3}){3}(\d{2})/, '$1.$2.$3-$+');
console.log(cpfFormatado); // 999.99.$3-99
How could I get to the same result as the first code using the second regular expression?