我有这个字符串:
<p><ins>Article </ins>Title</p>
<p>Here's some sample text</p>
我想将忽略 html 标签的单词放入数组,即
['Article','Title','Here's','some','sample','text']
我试图创建一个正则表达式,但它不会成功。 提前致谢。
最佳答案
将它们放入虚拟 div
中并获取 innerText
var str = `<p><ins>Article </ins>Title</p>
<p>Here's some sample text</p>`;
var div = document.createElement( "div" );
div.innerHTML = str; //assign str as innerHTML
var text = div.innerText; //get text only
var output = text.split( /\s+/ ); //split by one or more spaces including line feeds
console.log( output );
关于javascript - 正则表达式获取 HTML 标签之间的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47938095/