I have been searching SO to find the correct way to use a var as part of a regex
.
The idea is to get each of the searchable fields on the page and check if the text contains the search term, then if so, replace that portion of the text and wrap it in a styled span.
this is the part of the code which is not working correctly, "/\\"+src+"/gi",
$('.srch').each(function () {
var txt = $(this).text(),
src = $('#Srch_Srch_txt').val();
var s = txt.replace("/\\"+src+"/gi", '<span class=highlight>' + src + '</span>');
$(this).html(s);
})
Thank you in advance, Will.