const regex = /^https?:\/\/www\.google((\..{1,3}){1,2})\/(search\?)(?!flights|maps)(?!.*&tbm=(shop|fin|lcl)&).*/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^https?:\\\/\\\/www\\.google((\\..{1,3}){1,2})\\\/(search\\?)(?!flights|maps)(?!.*&tbm=(shop|fin|lcl)&).*', 'gm')
const str = `#images
https://www.google.com/search?q=finance&hl=en&tbm=isch&sxsrf=ALeKk03-wtxJ6IxBQ1QplyRfSUR5Zq6p5w:1588804525013&source=lnms&sa=X&ved=0ahUKEwjsstKKpqDpAhWIiqQKHeGbDWcQ_AUICygC&biw=2560&bih=1307&dpr=1
#books
https://www.google.com/search?q=finance&hl=en&sxsrf=ALeKk020ZKe6S8ZciwePz_FDqQNjlrIyMw:1588804501205&source=lnms&tbm=bks&sa=X&ved=2ahUKEwiuraX_paDpAhUHLBoKHbvWAKYQ_AUoAXoECBgQCQ&biw=2560&bih=1307
#all
https://www.google.com/search?q=finance&hl=en&sxsrf=ALeKk02-xP9nE6zHjjatj9fSG3th2_3zzw:1588804479887&source=lnms&sa=X&ved=0ahUKEwi0k5D1paDpAhWJ-qQKHW1XANcQ_AUIDSgA&biw=2560&bih=1307&dpr=1
#news
https://www.google.com/search?q=finance&source=lmns&tbm=nws&bih=1307&biw=2560&hl=en&ved=2ahUKEwi2jsnCpaDpAhWF44UKHcvnDusQ_AUoAXoECAEQAQ
####Dont match following
#finance
https://www.google.com/search?hl=en&biw=2560&bih=1307&tbm=fin&sxsrf=ALeKk00e_wrvwwyEY7nhVKV8j5IvHPK8rQ%3A1588802138647&ei=WjKzXuX1JofVkwWv-p24Dg&q=finance&oq=finance&gs_l=finance-immersive.3...980.1734.0.1817.7.5.0.0.0.0.208.208.2-1.1.0....0...1.1.64.finance-immersive..6.1.208...81.0.T31TXEhQon8
#flights
https://www.google.com/flights?q=testt&bih=1307&biw=2560&hl=en&tbm=flm&sxsrf=ALeKk03tMI1tx59I3Jc-LJfPj3_gEihKyA:1588801776819&source=lnms&sa=X&ved=0ahUKEwiugJrsm6DpAhVNDOwKHRFgCLkQ_AUINSgD#flt=/m/04jpl..2020-05-22*./m/04jpl.2020-05-26;c:GBP;e:1;ls:1w;sd:0;t:h
#maps
https://www.google.com/maps?hl=en&biw=2560&bih=1307&sxsrf=ALeKk00e_wrvwwyEY7nhVKV8j5IvHPK8rQ:1588802138647&q=finance&um=1&ie=UTF-8&sa=X&ved=2ahUKEwiY2IGanaDpAhVFCewKHYSIDCwQ_AUoAHoECAEQCA
#maps widget in search
https://www.google.com/search?q=finance&source=lmns&bih=1307&biw=2560&hl=en&ved=2ahUKEwjd86Po7qLpAhWFs3EKHVkiBy0QvS4wDnoECBEQHQ&sxsrf=ALeKk02paj14dQam1LLme0LY76me3nxOSw:1588892768213&npsic=0&rflfq=1&rlha=0&rllag=52234121,132579,226&tbm=lcl&rldimm=12043644416834703012&lqi=CgdmaW5hbmNlWhIKB2ZpbmFuY2UiB2ZpbmFuY2U&rldoc=1&tbs=lrf:!1m4!1u3!2m2!3m1!1e1!1m4!1u16!2m2!16m1!1e1!1m4!1u16!2m2!16m1!1e2!2m1!1e16!2m1!1e3!3sIAE,lf:1,lf_ui:2&rlst=f#rlfi=hd:;si:12043644416834703012,l,CgdmaW5hbmNlWhIKB2ZpbmFuY2UiB2ZpbmFuY2U;mv:[[54.130455193219696,5.088306911880459],[50.21534923934904,-6.66706418186956]]
#shopping
https://www.google.com/search?q=testt&source=lmns&tbm=shop&bih=1307&biw=2560&hl=en&ved=2ahUKEwiShpzrm6DpAhUW_hoKHQ61AEcQ_AUoAnoECAEQAg
https://www.google.com/
https://www.google.fr/
https://www.google.cm/
https://www.google.co.uk/`;
// 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