By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

Using var in reg exp

P: n/a
Hi All!

How can I use a var in a regular expression? For example, I want to do
something like this:

var stringToReplace = "replace me";
myString.replace(/ stringToReplace /gi, '');
Any suggestions would be most welcome!

Rob
:)
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Found my answer!
How can I use a var in a regular expression? For example, I want to do
something like this:

var stringToReplace = "replace me";
myString.replace(/ stringToReplace /gi, '');


var regularExpression = new RegExp("replace me", "gi");
myString.replace(regularExpression, '');

Rob
:)
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.