Remove "Www", "Http://" from String

remove http and https from string in php

This worked for me,

$http_referer = str_replace($removeChar, "", "https://example.com/");

How to remove 'http://' from a URL in JavaScript

I think it would be better to take into account all possible protocols.

result = url.replace(/(^\w+:|^)\/\//, '');

How to remove www, http/https and other strings in URL in C#

If you are working for Winforms then

string url = "http://www.merriam-webster.com/dictionary/sample";

UriBuilder ub = new UriBuilder(url);

MessageBox.Show(ub.Host.Replace("www.",""));

and for web,

Get host domain from URL?

Remove http:// and https:// from a string

server = server.(/^https?\:\/\/(www.)?/,'')

This didn't work, because you aren't calling a method of the string server. Make sure you call the sub method:

server = server.sub(/^https?\:\/\/(www.)?/,'')

Example

> server = "http://www.stackoverflow.com"
> server = server.sub(/^https?\:\/\/(www.)?/,'')
stackoverflow.com

As per the requirement if you want it to work with the illegal format http:\\ as well, use the following regex:

server.sub(/https?\:(\\\\|\/\/)(www.)?/,'')

PHP Regex to Remove http:// from string

$str = 'http://www.google.com';
$str = preg_replace('#^https?://#', '', $str);
echo $str; // www.google.com

That will work for both http:// and https://

Remove www , http:// from string

s = s.sub(/^https?\:\/\//, '').sub(/^www./,'')

If you don't want to use s =, you should use sub!s instead of all subs.

The problems with your code are:

  1. Question mark always follows AFTER an optional character
  2. Always replace one pattern in a sub. You can "chain up" multiple operations.
  3. Use sub instead of gsub and ^ in the beginning of Regexp so it only replaces the http:// in the beginning but leaves the ones in the middle.

How can I remove http or https using javascript

To remove just http/https: window.location.href.replace(/^http(s?)/i, "");

To remove http:/https:: window.location.href.replace(/^http(s?):/i, "");

To remove http:///https://: window.location.href.replace(/^http(s?):\/\//i, "");

These are all case-insensitive and only remove from the start of the string



Related Topics



Leave a reply



Submit