Technology?A site for testing the new tools I'm building, and a little talk about what I'm learning on the way. |
Javascript Replace All with VariableMonday, 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."; CommentsThere 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!
|
Related Topics See Also |