SaiKiran
SaiKiran

Reputation: 6504

Regex to exclude specific websites in javascript?

I have a regex which matches all the websites but i want to exclude 2 specific websites from this regex?

Regex is

[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)

Websites I want to exclude are

www.gfycat.com
www.imgur.com
imgur.com/*
gfycat.com/*

Is it possible to write the regex which exludes the specific websites? Any suggestions on how to solve this problem?

/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/

I have attached the screenshot for match patterns. enter image description here

Using RES and regex need to be implemented here.enter image description here

Upvotes: 0

Views: 150

Answers (2)

mkHun
mkHun

Reputation: 5927

Try this

^(?:(?!(?:www\.)?(?:google|gfycat|imgur))[-a-zA-Z0-9@:%._\+~#=]{2,256})\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)

Upvotes: 1

Sudipta Mondal
Sudipta Mondal

Reputation: 2572

Not sure, why you need regex to do the same. Can you not do something simple like the below, unless I understood it completely wrong.

url = new URL('https://www.google.co.uk/?gfe_rd=cr&ei=bN5IWaP7CYyDtAHKv4CIBg#q=hello');

if url.hostname == 'www.google.com'
// ignore
else
// process 

The answer is not relevant to the specific question as OP is using a different tool

Upvotes: 0

Related Questions