Link to home
Start Free TrialLog in
Avatar of Lakio
LakioFlag for Iceland

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(/.variabl/gi)  //can I have variable in here? <-- problem!

output   string="abcdefg"


hope somebody understand me :P, thx
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lakio

ASKER

thx, very good answer but g must be any letter (is that a .?)
Avatar of Lakio

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 :)