[英]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.