Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

taking off the http or https off a javascript string

Tags:

I have the following strings

http://example.com https://example.com http://www.example.com 

how do i get rid of the http:// or https://?

like image 774
Matt Elhotiby Avatar asked Oct 22 '10 18:10

Matt Elhotiby


People also ask

How do I remove the last url?

First you need to parse the tag. Next try to extract st_url value which is your url. Then use a loop from the last character of the extracted url and omit them until you see a '/'. This is how you should extract what you want.

How do I remove a link from text in Python?

sub(r'http\S+', '', my_string) . The re. sub() method will remove any URLs from the string by replacing them with empty strings.


2 Answers

Try with this:

var url = "https://site.com"; var urlNoProtocol = url.replace(/^https?\:\/\//i, ""); 
like image 60
ncardeli Avatar answered Oct 02 '22 15:10

ncardeli


You can use the URL object like this:

const urlWithoutProtocol = new URL(url).host;

like image 36
Vincent D'amour Avatar answered Oct 02 '22 14:10

Vincent D'amour