fork download
  1. let test = "I have 12 cars, 11 of which are 89 years old";
  2.  
  3. let x = test.replace(/\s\d+\s/g, (match) => {
  4. if (parseInt(match) % 2) return " BEEP ";
  5. else return match;
  6. });
  7.  
  8. console.log(x);
  9.  
Success #stdin #stdout 0.04s 16564KB
stdin
Standard input is empty
stdout
I have 12 cars, BEEP of which are BEEP years old