I need help with creating a regex pattern to find the word "bacon" after the first "/" in a URL.
Here are some examples:
Expected to return true:
console.log('1 - ', myRegexFunction('www.bacondelivery.com/weekly-bacon-delivery/'));
console.log('2 - ', myRegexFunction('www.bacondelivery.com/daily-bacon-delivery/'));
console.log('3 - ', myRegexFunction('www.bacondelivery.com/bacon-of-the-month-club/'));
Expected to return false:
console.log('4 - ', myRegexFunction('www.bacondelivery.com/'));
console.log('5 - ', myRegexFunction('www.bacondelivery.com/?some_param'));
console.log('6 - ', myRegexFunction('www.bacondelivery.com/about/'));
console.log('7 - ', myRegexFunction('www.bacondelivery.com/contact-us/'));
This is what I currently have:
function myRegexFunction(url) {
var regex = new RegExp("^([a-z0-9]{5,})$");
if (regex.test(url)) {
return true;
} else {
return false;
}
}
Any suggestions would be greatly appreciated!