空杯来酒,狗娘养的青春,重庆航道局
正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串、将匹配的子串做替换或者从某个串中取出符合某个条件的子串等。
则表达式:
var match = /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/;
匹配:
(1)、直接匹配域名地址:
var matchstring = 'https://i.cnblogs.com/'; console.log(match.test(matchstring)); // ==> true
(2)、匹配链接含(*.htm,*.html,*.php,*.aspx...)后缀的地址:
var matchstring = 'https://i.cnblogs.com/editposts.aspx'; console.log(match.test(matchstring)); // ==> true
(3)、匹配含参数的地址:
var matchstring = 'https://i.cnblogs.com/editposts.aspx?opt=1'; console.log(match.test(matchstring)); // ==> true
使用说明:
(1)、地址必须以http/https/ftp/ftps开头;
(2)、地址不能包含双字节符号或非链接特殊字符。
以上所述是小编给大家介绍的匹配url的正则表达式,希望对大家有所帮助
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Java正则相关的Pattern和Matcher类及遇到的坑
网友评论