Menu
Toggle navigation
Sign In
Edit
-
Delete
Back and Next - Back and Next
« Javascript DOM Ready for SSL in IE
New Projects for 2009 with News Statisti... »
Edit
-
Delete
Show Media Item - Javascript Replace All with Variable
Javascript Replace All with Variable
Monday, December 28, 2009
Here is how you replace all values in a string with another string which is inside of a variable using Javascript:
var str = "Please change all the change words in this sentence.";
var searchfor = "change";
str = str.replace(new RegExp(searchfor, 'g'), "changed");
The resulting value for str would be:
"Please changed all the changed words in this sentence.";
Edit
-
Delete
Related Topics - Related Topics
javascript
Edit
-
Delete
Media Actions - Media Actions
0
Promote
Email to a friend
Enquire
Edit
-
Delete
See Also - See Also