Friday, April 15, 2011

JavaScript Code Snippet: Find and Replace all

Here is a JavaScript code snippet for a find and replace all.

This example code finds if there is an instance of three dashes in the string and replaces with three spaces.


if(str.indexOf('---') != -1){
str = str.replace(/---/g,' ');
}

No comments: