Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
Replace text using regular expressions js vanilla

I am trying to replace the text of an input. If I enter this value (11111111), the output format should be (1,111,111-1). I have no idea how to do this using js vanilla. I am trying to use regex and replace but I'm very confused.

let regExp = /^[1-9].\d{3}.\d{3}-\d{1}$/g;  
let newInput = input.replace(regExp, '$1,');
console.log( newInput);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The regex is for the match, which must match the input string. Use the replacement pattern to reformat the output:

let input = '11111111'
let regExp = /^(\d)(\d{3})(\d{3})(\d)$/g;  
let newInput = input.replace(regExp, '$1,$2,$3-$4');
console.log( newInput);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda