Lakio
asked on
variable in RegExp //can anyone move this to "javascript"
Hi,
//fyrst I have a string
var string="abcg99defg";
//and a variable
var variabl=99;
now I like to replace g99 // that's the variable and 1 letter in front of it
with ''; //thats nothing
string=string.replace(/.va riabl/gi) //can I have variable in here? <-- problem!
output string="abcdefg"
hope somebody understand me :P, thx
//fyrst I have a string
var string="abcg99defg";
//and a variable
var variabl=99;
now I like to replace g99 // that's the variable and 1 letter in front of it
with ''; //thats nothing
string=string.replace(/.va
output string="abcdefg"
hope somebody understand me :P, thx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
var string="abcg99defg";
var variable=99;
var rx = new RegExp("." + variable, "gi");
string = string.replace(rx,'');
document.write(string);
thank you hernst this works fine :)
var variable=99;
var rx = new RegExp("." + variable, "gi");
string = string.replace(rx,'');
document.write(string);
thank you hernst this works fine :)
ASKER