JS intercept corresponding domain name----regular match method and check URL regular expression

Source: Internet
Author: User
Tags in domain

js intercept corresponding domain name----regular match method and check URL regular expression
use JavaScript to intercept the corresponding domain name method Two, for everyone to reference1. Method 1: [JavaScript] View plain copyfunctionDomainuri (str) {vardurl=/http:\/\/([^\/]+) \//i; Domain=Str.match (Durl); returnDomain[1]; } Call:vardomain=Domainuri (DOCUMENT.LOCATION.HREF); Console.log (domain); 2Method 2: [JavaScript] View plain copyvarUrlreg =/[a-za-z0-9][-a-za-z0-9]{0,62} (\.[ A-ZA-Z0-9][-A-ZA-Z0-9]{0,62}) +\.? /; varUrl=urlreg.exec ("Http://www.baidu.com/aaaa"); Console.log (url[0]); [JavaScript] View plain copy [JavaScript] view plain copy return result: Www.baidu.com (*^__^*hehe ..., write down the next time you use it, you can use it! Supplemental: Check URL regular expression [JavaScript] view plain copyfunctionisurl (URL) {varStrregex = "^ ((https|http): \/\/)?" + "(((((([0-9]|1[0-9]{2}| [1-9] [0-9]|2[0-4][0-9]|25[0-5]) [.] {1}) {3} ([0-9]|1[0-9]{2}| [1-9] [0-9]|2[0-4][0-9]|25[0-5])) "//ip> form of URL-199.194.52.184+ "|" + "([0-9a-za-z\u4e00-\u9fa5\uf900-\ufa2d-]+[.] {1}) +[a-za-z-]+) "//URL in domain form+ "(: [0-9]{1,4})?"//Port-:+ "((/?)| (/[0-9a-za-z_!~* ' ().;?: @&=+$,%#-]+) +/?)     {1}quot;;    var re=new RegExp (Strregex);     Console.log (re.test (URL));       return re.test (URL); }  

JS intercept corresponding domain name----regular match method and check URL regular expression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.