Quote:
Originally Posted by WolfShade
I don't think you can use a variable in regex.
One thing I did notice, however, is that if you're trying to replace more than just one instance of something, you can split on something, then join on "".
s.split(something);
s.join("");
This will replace all instances of variable something with "". If you have two or more spaces in the resulting string, then use regex to replace all double-or-more instances of space with just single space.
|
How is that different from / better than
Code:
var txt = "Here is something and something and something";
txt = txt.replace(/(\s)?something/gi,"");