How do you use the matched variables in the pattern in the replacement string?
var regexp = new RegExp('needle', 'ig'); str.replace(regexp, '<span class="marked">//1</span>')
try
var regexp = new RegExp(something, 'ig'); str.replace(regexp, '<span class="marked">$&</span>')
References:
A table specifying the format of different tokens to be used into the replacement string
An example on how to switch two words into a string
1.4m articles
1.4m replys
5 comments
57.0k users