clarkk clarkk - 1 year ago 102
Javascript Question

JavaScript String replace - How do you use matched variables in the replacement string?

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>')

Answer Source


var regexp = new RegExp(something, 'ig');
str.replace(regexp, '<span class="marked">$&</span>')


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download