const regex = /(\&|\?)(id=\d+)/s;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\&|\\?)(id=\\d+)', 's')
const str = `//detail.tmall.com/item.htm?abtest=&pvid=42b3a520-35a1-47f8-abe8-572bef4a430f&pos=1&abbucket=&acm=03054.1003.1.2768562&id=604432657613&scm=1007.16862.95220.23864_0_0&utparam=%7B%22x_hestia_source%22%3A%2223864%22%2C%22x_object_type%22%3A%22item%22%2C%22x_mt%22%3A0%2C%22x_src%22%3A%2223864%22%2C%22x_pos%22%3A1%2C%22x_pvid%22%3A%2242b3a520-35a1-47f8-abe8-572bef4a430f%22%2C%22x_object_id%22%3A604432657613%7D`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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