I would like to split a string that looks like:
This is <strong>a</strong> test <a href="#test">link</a> and <br /> line. break
into the following with JavaScript:
[
'This',
'is',
'<strong>a</strong>',
'test',
'<a href="#test">link</a>',
'<br />',
'line.',
]
I tried splitting on spaces, and <
>
, but that obviously doesn't work for tags like strong
and a
. I'm not sure how to write a regex that doesn't split within HTML tags. I also tried to use jQuery children()
, but it doesn't extract plain text, just the html tags. Any help would be great.