passing variable to a regexp in javascript
Possible Duplicate:
Escape string for use in Javascript regex
I have a msg like
Max {0} chars allowed in {1}
I have a function to create a message using the arguments passed as
for(var i = 0; i < agrs.length; i++){
reg = new RegExp('\{'+i+'\}', 'gi');
key = key.replace(reg,agrs[i])
}
The problem is that its not able to take the param "i" to create the reg exp.
Whats the way to achieve the same ?
Nrj
- 6.9k
- 7
- 49
- 59
lang-js