Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda