Другой вариант - использовать группу захвата вместо вида сзади:
::([^>]+)
Regex demo
Например
const regex = /::([^>]+)/g;
const str = `<foo::bar>`;
let m;
let match = [];
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
match.push(m[1]);
}
console.log(match.join(''));
Если вы хотите сопоставить весь шаблон строки, вы можете использовать:
<[^>]+::([^>]+)>
Regex demo
const regex = /<[^>]+::([^>]+)>/g;
const str = `<foo::bar>`;
let m;
let match = [];
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
match.push(m[1]);
}
console.log(match.join(''));