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

181
Visualizações
find all letters without repeating regex

help me please to find all letters in string without repeating using regex JS.

Examples:

let str = "abczacg";
str = str.match(/ pattern /); // return has to be: abczg

str = "aabbccdd" //return:abcd.

str = "hello world"//return: helo wrd

Is it possible?

Thank you!

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

0

Here is one approach. We can first reverse the input string. Then, do a global regex replacement on the following pattern:

(\w)(?=.*\1)

This will strip off any character for which we can find the same character later in the string. But, as we will be running this replacement on the reversed string, this has the actual effect of removing all duplicate letters other than their first occurrence. Finally, we reverse the remaining string again to arrive at the expected output.

var input = "abczacg";
var output = input.split("").reverse().join("").replace(/(\w)(?=.*\1)/g, "");
output = output.split("").reverse().join("");
console.log(output);

about 4 years ago · Juan Pablo Isaza Relatório

0

An alternative without using a regex using a Set:

[
  "abczacg",
  "aabbccdd",
  "hello world"
].forEach(s => {
  console.log([...new Set(s.split(''))].join(''))
})

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