I have a string in the form,
var k= '<html><div id="test">it is interesting</div></html>',
I am trying to convert this in to an array of form
<html>
<div id="test">
it
is
interesting
</div>
</html>
I am using Javascript to perform this task. I could use the split function a detect the space in between words to split the string, but how do I split the HTML tag.
Update: If your string can contain substring
"<>"(not valid in HTML) then try to use regular expression with minor changes:/(<.*?>)|([^ ]+?(?=[ <]))/gUpdate: If you need to interpret
\n\r\tsimbols (new line, carriage return, tab) as space try to use next regular expression:/(<.*?>)|(\S+?(?=[\s<]))/g(see also remark in above update about usage first*or+)