javascript - Get only domain from any URL -


my goal these urls:

https://www.facebook.com/ -> https://www.facebook.com/ http://www.facebook.com/ -> http://www.facebook.com/ https://www.facebook.com -> https://www.facebook.com https://www.facebook.com/awdawdaw/dawdwad -> https://www.facebook.com/ 

my regex is: /(https*:\/\/.+(\/|\b))/gi.

first 3 urls been returned well. when there after / character, match characters , don't want it. should next?

you use below negated character class based regex.

\bhttps?:\/\/[^\/]+\/? 

demo


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -