匹配URL的正则表达式(推荐)

2016-12-10 18:34:25  url正则表达式

正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串、将匹配的子串做替换或者从某个串中取出符合某个条件的子串等。

则表达式:

var match = /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/;

匹配:

(1)、直接匹配域名地址:

var matchString = 'https://iblogs-com/'; console.log(match.test(matchString)); // ==> true

(2)、匹配链接含(*.htm,*.html,*.php,*.aspx...)后缀的地址:

var matchString = 'https://iblogs-com/EditPosts.aspx'; console.log(match.test(matchString)); // ==> true

(3)、匹配含参数的地址:

var matchString = 'https://iblogs-com/EditPosts.aspx?opt=1'; console.log(match.test(matchString)); // ==> true

使用说明:

(1)、地址必须以http/https/ftp/ftps开头;

(2)、地址不能包含双字节符号或非链接特殊字符。

以上所述是小编给大家介绍的匹配URL的正则表达式,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

匹配URL的正则表达式(推荐)》阅读地址:http://www.haoshilao.net/12982/

最新图文教程: