All I have found that works at the moment is using spaces to match on. I would like to be able to match arbitrary HTML tags and punctuation.
var text = "<div>The Quick brown fox ran through it's forest darkly!</div>"
//this one uses spaces only but will match "darkly!</div>" as 1 element
console.log(text.match(/\S+/g));
//outputs: ["<div>The", "Quick", "brown", "fox", "ran", "through", "it's", "forest", "darkly!</div>"]
I want a matching expression that will output:
["<div>", "The", "Quick", "brown", "fox", "ran", "through", "it's", "forest", "darkly", "!", "</div>"]
Here is a fiddle: https://jsfiddle.net/scottpatrickwright/og0bd0xj/2/
Ultimately I am going to store all of the matches in an array, do some processing (add some span tags with a conditional data attribute around every whole word) and re-output the original string in an altered form. I mention this as solutions which don't leave the string more or less intact wouldn't work.
I am finding lots of near miss solutions online however my regex is not good enough to take advantage of their work.