How to use variable in a regular expression with JavaScript

1 Answer

0 votes
let s = "javascript java c c++ java c# java php"

const remove = "java"

const regex = new RegExp(remove, 'g'); 

s = s.replace(regex, ''); 
 
console.log(s); 
 
 

 
/*
run:
 
script  c c++  c#  php
 
*/

 



answered May 25, 2021 by avibootz
edited May 23, 2022 by avibootz
...