How to replace all occurrences of a word in a string with Node.js

3 Answers

0 votes
let s = "node.js php c++ PHP css c#";

s = s.replace(/ php/g, ' python');
 
console.log(s);
  

   
    
    
/*
run:
    
node.js python c++ PHP css c#
   
*/
   

 



answered Jan 23, 2022 by avibootz
0 votes
let s = "node.js php c++ PHP css c#";

s = s.replace(/ php/gi, ' python');
 
console.log(s);
  

   
    
    
/*
run:
    
node.js python c++ python css c#
   
*/

 



answered Jan 23, 2022 by avibootz
0 votes
let s = "node.js php c++ PHP css c#";

s = s.split('php').join('python');
 
console.log(s);
  

   
    
    
/*
run:
    
node.js python c++ PHP css c#
   
*/

 



answered Jan 23, 2022 by avibootz

Related questions

...