正则表达式 - javascript 二级域名正则
PHPz
PHPz 2017-04-10 16:43:26
0
2
370

以下这些域名,需要获取加黑加粗的部分

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

PHPz
PHPz

学习是最好的投资!

membalas semua(2)
PHPzhong

第二个加粗应该没加对吧

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);
阿神
var reg = /https?:\/\/(?:[^/]+\.)?([^./]+\.\w*.(?:cn|com|top|com\.tw))(?:$|\/)/

https://regex101.com/r/fP4xM3/3

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!