I am trying to find a regex, in order to wrap all the words of a text in spans. I am using the following code:
$this.html($this.text().replace(
/([^\s]*\s)/g, "<span>$1</span>"));
where this is referred to a div element. However, img and a elements, which are inside div, disappear. I tried to change the regex into:
$this.html($this.text().replace(
/([^(\s | <a.*/a> | <img.*/img>)]*\s)/g, "<span>$1</span>"));
but i didn't fix the problem.
Can someone help me?