Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Get hostname from a URL using JavaScript

Sometimes we may have strings which contain some UR;s and we may want to retrieve the hostname from the URLs for some statistic use. For example, we may have a URL : http://www.example.com/aboutus.html. We may want to retrieve the www.example.com from the URL. How? Use regular expression. Here I give an example using JavaScript. If you want to check whether a string is a URL or not. Refer to Detect URLs in a Block of Text. In JavaScript, we can have a regular expression like var pattern=/(.+:\/\/)?([^\/]+)(\/.*)*/i;the regular expression pattern can be used to get the hostname. There are three...

18,448 0       JAVASCRIPT REGULAR EXPRESSION URL HOSTNAME