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

124
Visualizações
Amending function so it can replace the required sentence

I need help in making this function be able to replace not only a single word ("apple" to "orange"), but a whole sentence too ("eat apple" to "sleep well"), both for regular and UPPERCASE. I've tried this :

const re = /eat_apple/gi;
const str = "eat apple";

const replacer = (match) => {
    if(match === "eat apple") {
        return "sleep well";
    }
    else if(match === "EAT APPLE") {
        return "SLEEP WELL";
    }
    else {
        return "eat apple";
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Check out case-insensitive string comparison. You can check the lowercased string, then do the replacement.

If you need the capitalization to somehow match the capitalization as it was originally, specify that by editing your question.

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