Javascript 用于检查URL是否为主URL的正则表达式
我正在寻找一个正则表达式来检查URL是否是主URL 有效Javascript 用于检查URL是否为主URL的正则表达式,javascript,regex,url,Javascript,Regex,Url,我正在寻找一个正则表达式来检查URL是否是主URL 有效 http://example.com https://example1.com https://example2.com/ http://anything.com/?test=12 http://anything.com?test=12 http://example.com/path https://example.com/path1/path2 https://example.com/path1?test=123 无效 http:/
http://example.com
https://example1.com
https://example2.com/
http://anything.com/?test=12
http://anything.com?test=12
http://example.com/path
https://example.com/path1/path2
https://example.com/path1?test=123
无效
http://example.com
https://example1.com
https://example2.com/
http://anything.com/?test=12
http://anything.com?test=12
http://example.com/path
https://example.com/path1/path2
https://example.com/path1?test=123
您可以使用此正则表达式:
/^https?:\/\/[^\/]+\/?(\?.*)?$/gm