我正在使用以下正则表达式验证URL.我也想验证google.com,但它返回false.可以在下面的RE中更改以验证google.com.
console.log(learnRegExp('http://www.google-com.123')); // false
console.log(learnRegExp('https://www.google-com.com')); // true
console.log(learnRegExp('http://google-com.com')); // true
console.log(learnRegExp('http://google.com')); //true
console.log(learnRegExp('google.com')); //false
function learnRegExp(){
return /^(ftp|https?):\/\/+(www\.)?[a-z0-9\-\.]{3,}\.[a-z]{3}$/.test(learnRegExp.arguments[0]);
}
Run Code Online (Sandbox Code Playgroud)