I am trying to remove
http://localhost:7001/
part from
http://localhost:7001/www.facebook.com
to get the output as
www.facebook.com
what is the regular expression that i can use to achieve this exact pattern?
You don't need any library or REGEX
var url = new URL('http://localhost:7001/www.facebook.com')
console.log(url.pathname)
https://developer.mozilla.org/en-US/docs/Web/API/URL
Based on @atiruz answer, but this is
url = url.replace( /^[a-zA-Z]{3,5}\:\/{2}[a-zA-Z0-9_.:-]+\//, '' );
To javascript you can use this code:
var URL = "http://localhost:7001/www.facebook.com";
var newURL = URL.replace (/^[a-z]{4,5}\:\/{2}[a-z]{1,}\:[0-9]{1,4}.(.*)/, '$1'); // http or https
alert (newURL);
Look at this code in action Here
Regards, Victor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With