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

need help with a "replace" function

P: n/a
Here's my code:

###
myvar = "test1_1;test2_1;test3_1";
myvar = myvar.replace(/_1/g, "_2")';
###

it works just fine. if I introduce "cat = 1", how do I change my
replace function so that instead of replacing a fixed "1" value, I
would use "cat"?

myvar = myvar.replace('/_'+cat'/g', "_2")' does not work.

Thanks!

Jul 9 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
figured it out myself:

myvar = "test1_1;test2_1;test3_1";
cat = "1"
myregexp = new RegExp("_"+cat, "g")
myvar = myvar.replace(myregexp, "_2")';

:)
na************@msn.com wrote:
Here's my code:

###
myvar = "test1_1;test2_1;test3_1";
myvar = myvar.replace(/_1/g, "_2")';
###

it works just fine. if I introduce "cat = 1", how do I change my
replace function so that instead of replacing a fixed "1" value, I
would use "cat"?

myvar = myvar.replace('/_'+cat'/g', "_2")' does not work.

Thanks!
Jul 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.