JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="s" value="тЕ">
<pre id="out"></pre>
JavaScript
const strings = ["ТЕСТ","Строка", "String", "протестеровано"]
const prefix = '<b>'; // во что оборачивать найденные подстроки
const suffix = '</b>';
foo(); // только для демо, срабатывает при старте и при измененнии searc
s.oninput = foo;
function foo() {
const search = s.value;
const modified = strings.map(str => { // перебираем строки
if (search.length < 1) return str;
const re = new RegExp(search, 'gi') // регулярка на основе search
return str.replace(re, bar); // для замены вызывается ф-ция bar
});
output(modified); // вывод для демо
}
function bar(match) {
return prefix + match + suffix; // оборачиваем найденные фрагменты
}
function output(data) {
out.textContent = JSON.stringify(data, null, 4);
}