I have a string and I need to find out what was matched in the string. For example:
var txt = "Hello world!";
txt.replace(/[a-h]/gi, '<span>' + TEXT_MATCHED + '</span');
I would like the output to be… <span>H</span><span>e</span>llo worl<span>d</span>!
try
(step 1: group the matched stuff using brackets. step 2: use $1 for the first matched group)