Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!