Skip to content

Instantly share code, notes, and snippets.

@unknownuser88
Created January 6, 2014 13:24
Show Gist options
  • Save unknownuser88/8282850 to your computer and use it in GitHub Desktop.
Save unknownuser88/8282850 to your computer and use it in GitHub Desktop.
replace(regexp/substr, replacetext) Searches and replaces the regular expression (or sub string) portion (match) with the replaced text instead.
//replace(substr, replacetext)
var myString = '999 JavaScript Coders';
console.log(myString.replace(/JavaScript/i, "jQuery"));
//output: 999 jQuery Coders
//replace(regexp, replacetext)
var myString = '999 JavaScript Coders';
console.log(myString.replace(new RegExp( "999", "gi" ), "The"));
//output: The JavaScript Coders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment