const regex = /\/(?<form>[^\/]*)\/\d+\/(?<rule>[^\/]*)\/\w+\/(?<mode>[^\/]*)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\\/(?<form>[^\\\/]*)\\\/\\d+\\\/(?<rule>[^\\\/]*)\\\/\\w+\\\/(?<mode>[^\\\/]*)', 'g')
const str = `http://linear-scope010.abc.com/LIVE/1002/hls/ae/TWAMCPH/98.m3u8
http://mmdai-linear-west-03.abc.com/linear-scope010.abc.com/LIVE/1008/hls/ae/Nat_HD/.swn71c39e69-9b76-45a0-a2da-005056b23b1dapple2apple/.rate_2737280/index_v_2737280_6.m3u8?nw=376521≺of=376521:twc_hls_live&mode=live&vdur=600&caid=NGC_LIVE&csid=stva_android_ph_live&vcid=369573a4-4f5b-3aa7-a42b-2eec0477efda&z5=79912&ads=VAST_LIVE&tagset_name=VAST&_fw_lpu=http://linear-scope010.abc.com/LIVE/1008/hl...`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions