如何在全局范围内为字符串应用 between 操作
how to apply a between operation globally for a string
我有一个包含多个 table 标签的 html 字符串。
String str = '<table>......</table> <table>....</table>';
当我使用 string.js 和以下代码时。
S(str).between('<table>', '</table>').s,
我只得到字符串的第一个 table 元素。我需要获取所有 table 元素(可能作为数组)。这可能与 stringjs 吗?
使用 stringjs 还是使用正则表达式更好?
我会说您需要拆分大字符串,删除出现的 <table>
和 </table>
,然后映射生成的数组。像
const str = '<table>......</table> <table>....</table>';
const subs = str.split('<table>').map(substring => substring.replace('</table>', ''));
console.log(subs); // -> ['......', '....']
它只有在你有一个代表许多 table
兄弟姐妹的巨大字符串时才有效,而这正是你所要求的。
我有一个包含多个 table 标签的 html 字符串。
String str = '<table>......</table> <table>....</table>';
当我使用 string.js 和以下代码时。
S(str).between('<table>', '</table>').s,
我只得到字符串的第一个 table 元素。我需要获取所有 table 元素(可能作为数组)。这可能与 stringjs 吗? 使用 stringjs 还是使用正则表达式更好?
我会说您需要拆分大字符串,删除出现的 <table>
和 </table>
,然后映射生成的数组。像
const str = '<table>......</table> <table>....</table>';
const subs = str.split('<table>').map(substring => substring.replace('</table>', ''));
console.log(subs); // -> ['......', '....']
它只有在你有一个代表许多 table
兄弟姐妹的巨大字符串时才有效,而这正是你所要求的。