I'm attempting to split a string by spaces into an array of words. If the string contains HTML tags, I would like the full tag (including content) to be treated as a single word.
For example,
I like to eat <a href="http://www.waffles.com/">tasty delicious waffles</a> for breakfast
should split into
I
like
to
eat
<a href="http://www.waffles.com/">tasty delicious waffles</a>
for
breakfast
I've seen a couple related threads on Stack Overflow but I'm having trouble adapting anything to Javascript because they were written for languages that I'm not quite familiar with. Is there a regex expression that could easily do this or will the solution require multiple regex splits and iteration?
Thanks.
<div> foo <div> bar </div> baz </div>
? – Tim Pietzcker Sep 26 '11 at 8:15