KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to perform a global replace of string using String.replace in Javascript. In the documentation I read that I can do this with /g, i.e. for example; var mystring = mystring.replace(/test/g, mystring); and this will replace all occurrences inside mystring. No quotes for the expression. But if I have a variable to find, how can I do this without quotes? I've tried something like this: var stringToFind = "test"; //first try mystring = mystring.replace('/' + stringToFind + '/g', mystring); //second try, not much sense at all mystring = mystring.replace(/stringToFind/g, mystring); but they don't work. Any ideas?
Tags (comma-separated)
Save Edits
Cancel