How can we shrink the URL in JavaScript:
for example if the link was like this, it should not extend after .com
Expected Output:
https://stackoverflow.com
Thanks for your time,
Solution: I have used Regexp to shrink the url
const yourUrl = {your url goes here}
const reConstructUrl = new RegExp(
[
"^(https?:)//", // protocol
"(([^:/?#]*)(?::([0-9]+))?)", // host (hostname and port)
'(/{0,1}[^?#]*)', // pathname
'(\\?[^#]*|)', // search
'(#.*|)$' // hash
].join("")
)
const matchedUrl = yourUrl.match(reConstructUrl);
Now you can display only the part you want from the URL