我正在尝试将这样的 html 拆分为字符串:
<p class='class1'> Hello, this is my html </p>
我需要的是通过空格分割该html,忽略分割中的html标签,我目前得到这个结果:
["<p","class='class1'>","Hello,","this","is","my","html","</p>"]
但我需要它将标签视为一个完整的单词,以获得这个结果:
["<p class='class1'>","Hello,","this","is","my","html","</p>"]
我怎样才能得到这个结果?
编辑:
在 javascript 方面,我使用了一个简单的拆分:
var text = "<p class='class1'> Hello, this is my html </p>";
var splitText = text.split(' ');
在这种情况下 splitText 将是:
["<p","class='class1'>","Hello,","this","is","my","html","</p>"]
我尝试使用像 "/[<.*?>,\s]+/" 这样的正则表达式,但我的结果是:
var text = "<p class='class1'> Hello, this is my html </p>";
var splitText = text.split(/[<.*?>,\s]+/);
splitText = ["p class='class1'","Hello,","this","is","my","html","/p"]
提前致谢。