Thread: regex variable
View Single Post
Old 12-08-2012, 08:58 AM   PM User | #8
rdspoons
New Coder

 
Join Date: Jun 2009
Posts: 81
Thanks: 0
Thanked 8 Times in 8 Posts
rdspoons is on a distinguished road
For what it's worth, you can also use eval to use variables in replace.


string.replace(eval("/"+somevar+"/gi"),"replacementString")

Code:
alert(
	(function(){
		var rvar = " simple";
    		return "This is a simple example with a simple string".replace(eval("/"+rvar+"/gi"),"n evaled")
	})()
);
rdspoons is offline   Reply With Quote
Users who have thanked rdspoons for this post:
Philip M (12-08-2012)