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

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -

javascript - three.js lot of meshes optimization -