const regex = /.*(\?)/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('.*(\\?)', '')
const str = `/maple-lodge-luxury-bed-and-breakfast/hotel/wanaka-nz.html?asq=1rrVgHWD%2ftbMPIK6tfFoOBewg1Z5%2buLS%2bSEDbaA%2fbS1Cje5wmB0pR0%2bLKktHrg4HC2IQVGwjWisHJHwdUYn88XKp1eogKj%2fzaqwNenpp8R5J8sYcWQ4ELgyWRz8zKFhqCpAzJy%2bIPcIhZIlXClDyysYo7iqvOXmWbg%2fTJAqzGDB7np8MbTsvr9hmeUc%2bP9lIlRlyZyrcrq%2fMBp7AbaEJbA%3d%3d&hotel=99830&tick=637329177909`;
// 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