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

215
Visualizações
How do I remove the characters in a string that are included in another string

How do I remove the characters in a string that are included in another string?

let mustRemoved = "rin8cu73s9b";
let string = "CatsAndDogsAreAwesome"

Output Must Be : atAdDogAeAweome

What I have tried:

let regEx = new RegExp(mustRemoved, "ig");
let replaceMask = "";
let final = string.replace(regEx, replaceMask);
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can convert the string into an array of characters, filter out the characters which are included in mustRemoved, then join the resulting array.

let mustRemoved = "rin8cu73s9b".toLowerCase();
let string = "CatsAndDogsAreAwesome"

let res = [...string].filter(e => !mustRemoved.includes(e.toLowerCase())).join('')
console.log(res)

about 4 years ago · Juan Pablo Isaza Relatório

0

You need to change your regex so that it matches with every character in mustRemoved string, like this:

let mustRemoved = "rin8cu73s9b";
let string = "CatsAndDogsAreAwesome"
let regEx = new RegExp(mustRemoved.split('').join('|'), "ig");
let replaceMask = "";
let final = string.replace(regEx, replaceMask);
console.log(final)

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