javascript "The replace() method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function called for each match. If pattern is a string, only the first occurrence will be replaced.". replace(/(replace\(\)|pattern|replacement)/ig, "span class='highlight'$1\/span")
javascript var str = "(replace\\(\\)|pattern|replacement)"; var reg = new RegExp(str, "gi"); "The replace() method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function called for each match. If pattern is a string, only the first occurrence will be replaced.". replace(reg, "span class='highlight'$1\/span")
javascript var data = { p1: "replace()", p2: "replacement", p3: "pattern"}; "The {{p1}} method returns a new string with some or all matches of a pattern replaced by a {{p2}}. The {{p3}} can be a string or a RegExp, and the {{p2}} can be a string or a function called for each match. If {{p3}} is a string, only the first occurrence will be replaced.". replace(/\{\{\s*(.*?)\s*\}\}/gi, function(str, ...args){ return data[args[0]];})