How to use variable in a regular expression with Node.js

1 Answer

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

 



answered May 23, 2022 by avibootz
...