Regular Expressions:
var match =/^ ((ht|f) tps?): \ /\/([\w\-]+ (\.[ \w\-]+) *\/) *[\w\-]+ (\.[ \w\-]+) *\/? (\? ([\w\-\.,@?^=%&:\/~\+#]*) +)?/;
Note:
(1), if you need to allow other connection methods, you can modify the "(Ht|f) TPS?" section, in the "?" Follow the symbol "|" followed by the Join method you need , with the symbol "|" Separated).
(2), if you want to allow the URL parameter contains other characters, you can modify "[\w\-\.,@?^=%&:\/~\+#]" To set the parameters you need.
*/
The:
(1), directly match the domain name address:
var matchstring = ' https://i.cnblogs.com '; Console.log (Match.test (matchstring)); ==> true
var matchstring = ' https://i.cnblogs.com/'; Console.log (Match.test (matchstring)); ==> true
var matchstring = ' https://i.cnblogs.com//'; ==> does not allow double "/" in places other than domain names or parameters; Console.log (Match.test (matchstring)); ==> false
(2), matching links included (*.htm,*.html,*.php,*.aspx ...) Address of suffix:
var matchstring = ' https://i.cnblogs.com/EditPosts.aspx '; Console.log (Match.test (matchstring)); ==> true
var matchstring = ' https://i.cnblogs.com./EditPosts.aspx '; ==> does not allow a double "." In places other than parameters. End; Console.log (Match.test (matchstring)); ==> false
(3), matching the address with parameters:
var matchstring = ' https://i.cnblogs.com/EditPosts.aspx?opt=1 '; Console.log (Match.test (matchstring)); ==> true
var matchstring = ' https://i.cnblogs.com/EditPosts.aspx?opt=1&user= ' Console.log (match.test (matchstring)); ==> true
Instructions for use:
(1), address must start with Http/https/ftp/ftps;
(2), the address cannot contain double-byte symbols or non-linked special characters.
Regular expression matching URL