佚名通过本文主要向大家介绍了javascript二级菜单,javascript二级联动,javascript正则表达式,javascript 正则,javascript正则匹配等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题:javascript 二级域名正则
描述:
解决方案1:
描述:
以下这些域名,需要获取加黑加粗的部分
http://w.nnn.cn/
http://www.meilishuo.top/
http://m.meilishuo.com/share/item_detail/3924101135?tab=0
http://product.m.dangdang.com/1181352912.html?
https://h5.m.taobao.com/guang/item.html?spm=a310p.7403370.19980966
http://item.jd.com/1903997.html
http://show.jd.com.cn/1903997.html
http://m.jd.com.tw/1903997.html
https://detail.m.tmall.com/item.htm?spm=a222m.7628550.0.0
解决方案1:
var reg = /https?:\/\/(?:[^/]+\.)?([^./]+\.\w*.(?:cn|com|top|com\.tw))(?:$|\/)/
https://regex101.com/r/fP4xM3/3
解决方案2:第二个加粗应该没加对吧
var text = `http://w.nnn.cn/ http://www.meilishuo.top/
http://m.meilishuo.com/share/item_detail/3924101135?tab=0
http://product.m.dangdang.com/1181352912.html?
https://h5.m.taobao.com/guang/item.html?spm=a310p.7403370.19980966
http://item.jd.com/1903997.html
http://show.jd.com.cn/1903997.html
http://m.jd.com.tw/1903997.html
https://detail.m.tmall.com/item.htm?spm=a222m.7628550.0.0`;
var urls = text.split(/\s/g);
var domains = urls.map(url => url.match(/((?:\w+\.){2}(?:cn|top|com\.cn|com\.tw|com))/)[1]);
console.log(domains);