<span class="c56 c77 c98">текст</span>
<span class="c101">текст</span>
<span class="c111">текст</span>
<span class="c12 c30 c98">текст</span>
<b>текст</b>
<b>текст</b>
<span class="c111">текст</span>
<b>текст</b>
const tempalte = `
<span class="c56 c77 c98">текст</span>
<span class="c101">текст</span>
<span class="c111">текст</span>
<span class="c12 c30 c98">текст</span>
`;
const parser = new DOMParser();
const root = parser.parseFromString(tempalte, 'text/html');
root.querySelectorAll('.c77, .c98, .c101').forEach((element) => {
const content = document.createElement('b');
content.append(...element.childNodes);
element.replaceWith(content);
});
console.log(root.body.innerHTML);
/*
<b>текст</b>
<b>текст</b>
<span class="c111">текст</span>
<b>текст</b>
*/
const template = `
<span class="c56 c77 c98">текст</span>
<span class="c101">текст</span>
<span class="c111">текст</span>
<span class="c12 c30 c98">текст</span>
`.trim();
const classNames = ['c77', 'c98', 'c101'];
let result = template;
for (const className of classNames) {
const expression = new RegExp(`<([\\w-]+)\\s*class=".*${className}.*"\\s*>(.+)</\\1>`, 'gm');
result = result.replace(expression, (match, tag, content) => `<b>${content}</b>`);
}
const classNames = ['c77', 'c98', 'c101'];
const expression = new RegExp(`<([\\w-]+)\\s*class=".*(${classNames.join('|')}).*"\\s*>(.+)</\\1>`, 'gm');
const result = template.replace(expression, (match, tag, className, content) => `<b>${content}</b>`);