var slovo = 'javascript'; var search = 'vas'; var regex = new RegExp(search); var result = regex.test(slovo) ? slovo.replace(search, '<b>' + search + '</b>') : slovo; alert(result);