If you are doing this the browser I would recommend you do not use regular expressions but instead use the DOM handling capabilites built into the browser. (There are good reasons for not using RegExp for parsing HTML, see this stackoverflow answer to get a first impression)
When you walk through the DOM tree you can use nodeType to distinguish between nodes that are Tags (called "element nodes") and nodes that only contain text.
div = document.querySelector('div');
for( let child of div.childNodes ) {
if (child.nodeType == Node.TEXT_NODE && /\w/.test(child.data) ) {
console.log("type", child.nodeType, "for", child.data);
let newChild = document.createElement('span');
newChild.textContent = child.data;
div.replaceChild(newChild, child)
}
}
See this codepen