How to use variable in a regular expression with TypeScript

1 Answer

0 votes
let s = "typescript java c c++ java c# java php"
 
const remove = "java"
 
const regex = new RegExp(remove, 'g'); 
 
s = s.replace(regex, ''); 
  
console.log(s); 
  
  
 
  
/*
run:
  
"typescript  c c++  c#  php" 
  
*/*/

 



answered May 23, 2022 by avibootz

Related questions

...