I am faced with two problems. (with jQuery)
for (var i=0; i<len; i++) {
var e = arr[i], //<- strings
re = new RegExp(e,"ig");
target.html(
target.html().replace(
re, "<span class='rep'>" + e + "</span>"
)
);
}
- The original value cannot be called after replacing. (like a “$1”)
- It cannot replace, if the candidate for substitution (property e) has a single quote.
You actually can use something similar to
$1:Your second problem is less clear to me. Single quotes are not special characters in regexes.
I could not replicate your other problem. Here is a working example: http://jsfiddle.net/Xsjt7/1/