var a = 'http://www.baidu.com/aaa.com'; var b = 'https://aaa.com/img/01.png'; var c = 'http://a.bbb.com/img/02.jpg'; var reg = /^https{0,1}:\/\/(aaa|bbb|ccc)\.com.*/; console.log(reg.test(a)); //false console.log(reg.test(b)); //true console.log(reg.test(c)); //false
试试这个:
不含http时可以匹配
应该符合你的要求
可以看下http://www.bcodey.com/?p=639
/^https?://(aaa|bbb|ccc).com.*/