Python regex for detecting all the urls excluding certain domains -


i have python regex detects urls:

r'(http[s]?://(?:[a-za-z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fa-f][0-9a-fa-f]))+)' 

but need exclude youtube , vimeo url detection. can do?

you can use negative look-ahead :

(http[s]?://(?!youtube|vimeo)(?:[a-za-z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fa-f][0-9a-fa-f]))+) 

see demo https://regex101.com/r/jb7tn3/1


Comments