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

157
Visualizações
Regex to replace digits with a character x times the match's length

Got the regex (?<!a|\d)[0-9]{6,} to match any digits with 6 in length or more, but that do not start with \ or digits.

Previously, I used I used [0-9] in replace("[0-9]", "x"), and it would replace 111 with xxx.

But now with the new formula replace("(?<!a|\d)[0-9]{6,}", "x") it just replaces with one x.

How can I make it so it continues the old behavior? I tried to use a function but it did not seem to work very well (using Zoho mail which uses weird JS language)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use a function as the replacement. It can then repeat the character the same number of times as the length of the match.

console.log('123456'.replace(/(?<!a|\d)[0-9]{6,}/g, match => "x".repeat(match.length)));

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