I need help in the code. what am I doing wrong?
Afficher commentaires plus anciens
I am writing a function to display host name from the url. This function should return only hostname without the port number
eg
Output: en.wikipedia.org
or
Input: http://www.google.com
Output: www.google.com
My code so far
function [result] = url2hostname(url)
c1 = strfind(url,'//');
ind1 = strfind(url,'/');
if isempty(c1) && isempty(ind1)
result = url;
return;
end
if ~isempty(c1)
if numel(ind1)>2
result = url(1:ind1(3)-1);
else
result = url;
end
else
result = url(1:ind1(1)-1);
end
return;
result = result;
Réponse acceptée
Plus de réponses (1)
This may help:
fnc = @(url) regexp(url, "(?<=https?://)(.*?)[^:]*", 'match');
fnc('https://en.wikipedia.org:443/wiki/Kitten?printable=yes&download=no#External_links')
fnc('http://www.google.com')
Catégories
En savoir plus sur Programming Utilities dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!