jquery - Replacing all match in a String -


this question has answer here:

my string contains variables given between @,eg:-(@name@). passing variables values , storing in array. want replace values variable in actual string.

this code

actual_string = actual_string.replace(new regexp('@'+dynamic[i]+"@"),value); 

this replace 1 value, if have same variable repeatedly above code replace first occurance. tried

actual_string = actual_string.replace(new regexp('/\@'+dynamic[i]+"\@/"),value); 

but not replacing single variable

you need use flags parameter of regexp. use g make search global throughout string. try this:

actual_string = actual_string.replace(new regexp('@' + dynamic[i] + "@", 'g'), value); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -