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