[英]Javascript RegEx - Split using text between tags
我正在處理腳本,需要拆分同時包含html標簽和文本的字符串。 我正在嘗試隔離標簽並消除文本。
例如,我想要這樣:
string = "<b>Text <span>Some more text</span> more text</b>";
像這樣拆分:
separation = string.split(/some RegExp/);
並成為:
separation[0] = "<b>";
separation[1] = "<span>";
separation[2] = "</span>";
separation[3] = "</b>";
我將不勝感激任何幫助或建議。
您可能需要改用String.match
:
var str = "<b>Text <span>Some more text</span> more text</b>";
var separation = str.match(/<[^]+?>/g);
console.log(separation); // ["<b>", "<span>", "</span>", "</b>"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.