• Sign In

Technology?

A site for testing the new tools I'm building, and a little talk about what I'm learning on the way.

Search
  • Home
  • TechnologyView my occasional technology posts.
  • Life
  • Contact
Edit - Delete
Back and NextBack and Next - Back and Next
« Javascript DOM Ready for SSL in IE
New Projects for 2009 with News Statisti... »
Edit - Delete
Show Media ItemShow 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
CommentsComments - Comments
Comments
 
There are 8 comments - add your comment
Mihir - Thursday, March 18, 2010 6:30 AM
Very useful thanks
Eytibi - Meckenheim, Westphalia - Thursday, July 22, 2010 1:10 PM
Works!

Thank you
Paul - Europe, World - Thursday, August 12, 2010 10:41 AM
exactly what i have searching for, and in a way that was so easy to understand. thank you very much :)
richa - Asia, World - Thursday, December 30, 2010 10:12 AM
Awesome
Ger - South America, World - Wednesday, May 04, 2011 2:53 PM
Excelent!!! Just what i needed
vikram - South America, World - Wednesday, June 01, 2011 10:42 AM
I want replace + symbol as plus in javascript
Osama Al Sallal - Asia, World - Sunday, July 17, 2011 7:36 AM
save my time, thanks
Chris - Europe, World - Thursday, January 26, 2012 9:11 PM
Thanks very much!

Your Comment

Your Name

Your Location

To receive emails create a username or Sign In
Your Email
Username
Password
Confirm Password
Add me to the contact list.
Remember me on this computer.
Sign in below or Sign Up
Username
Password
loading...  Post Comment
 
Edit - Delete
Related TopicsRelated Topics - Related Topics
Related Topics
javascript
Edit - Delete
Media ActionsMedia Actions - Media Actions
Media Actions
0
Promote
Email to a friend
Inquire
Save to delicious
Digg this
Stumble it
Edit - Delete
See AlsoSee Also - See Also
See Also

Try Lara

Build your own website with Lara.  A powerful content management system with easy and fun to use design tools. 

Visit http://getlara.com to learn more.

Go here for a good Javascript Html Editor.

Subscribe Now

Recent Posts

  • Ultimate Frisbee Mauritius
  • The best free icon collection on the internet - Icons Etc.
  • VGA Planets "Nu" - The official VGA Planets remake
  • Sending Email from Amazon EC2
  • Using SSL (https) with Mono HTTPListener
  • .NET MimeTypes Class in C#
  • Great WordPress Plugins
  • Flash IO Error #2038 when Uploading Files in .NET
  • Javascript DOM Ready for SSL in IE
  • Javascript Replace All with Variable
Website created with Lara by Geographical Media