const regex = /(?:(?!video).)*video\/(\d+)\//gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:(?!video).)*video\\\/(\\d+)\\\/', 'gm')
const str = `https://www.iesdouyin.com/share/video/7039240821144702223/?region=CN&mid=7039240839087803150&u_code=19ambj1ae&did=MS4wLjABAAAAif33DuCPz8E4TM8ohLFknanLbAaeYNGHZvIMdpUGZBk&iid=MS4wLjABAAAAbcVu-zX1os-3_V1-tnqKfcfhYUGKXPsJhcECdsvolcDBQetzxujmh6J5MwxRPIAa&with_sec_did=1&titleType=title×tamp=1639030688&utm_campaign=client_share&app=aweme&utm_medium=ios&tt_from=copy&utm_source=copy
{START}(?:(?!{END}).)*{END}`;
// 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