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

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

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 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