一个正则匹配的问题

阅读 3.3k
5 个回答

试试这个:

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
新手上路,请多包涵
/^(\w*:\/\/)?w*\.?(aaa|bbb|ccc)\.com/.test()

不含http时可以匹配

var str = location.protocol+location.hostname;

var reg = new RegExp("/^https://www\.(aaa|bbb|ccc)\.com$/i");

var result = reg.test(str);

应该符合你的要求

新手上路,请多包涵

/^https?://(aaa|bbb|ccc).com.*/

推荐问题