How to convert multiple words in a string to uppercase in Node.js

2 Answers

0 votes
let str = "The Worlds most reliable Programming Q&A website worlds";
  
const the_word = "Worlds|reliable";

const re = new RegExp(the_word, "gi");
 
str = str.replace(re, function UpperCase(s) { return s.toUpperCase(); });
   
console.log(str);
 
 
 
                    
/*
run:
  
The WORLDS most RELIABLE Programming Q&A website WORLDS
   
*/

 



answered May 22, 2022 by avibootz
0 votes
let str = "The Worlds most reliable Programming Q&A website worlds";
  
str = str.replace(/Worlds|reliable/gi, function UpperCase(s) { return s.toUpperCase(); });
   
console.log(str);
 
 
 
                    
/*
run:
  
The WORLDS most RELIABLE Programming Q&A website WORLDS
   
*/

 



answered May 22, 2022 by avibootz
...