Javascript String replaceAll(str1, str2, ignore)

Description

Javascript String replaceAll(str1, str2, ignore)


/**// w  w  w  . j a  v  a2  s.co m
 * Replace all content
 */
String.prototype.replaceAll = function(str1, str2, ignore) {
    return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignore?"gi":"g")),(typeof(str2)=="string")?str2.replace(/\$/g,"$$$$"):str2);
};



PreviousNext

Related