function getTestIndex(domain, string) {
var result = RegExp("^(?:@|(?:https?:\/\/)?(?:www\.)" + domain + "?\(\w+)\/?$").exec(string);
return result[1];
}
console.log(getTestIndex('testdomain.com', 'https://testdomain.com/testindex'));
function getTestIndex(domain, string) {
const regex = new RegExp(`^(?:@|(?:https?://)?(?:www\\.)?${domain}/?(\\w+)?)$`);
const result = regex.exec(string);
return result ? result[1] : null;
}
console.log(getTestIndex('testdomain.com', 'https://testdomain.com/testindex'));