php抓取网页匹配url( 2016年11月23日10:44:18字符串匹配的模式)

优采云 发布时间: 2021-12-24 10:04

  php抓取网页匹配url(

2016年11月23日10:44:18字符串匹配的模式)

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

  更新时间:2016年11月23日10:44:18 作者:Kris゜

  正则表达式描述了一种字符串匹配模式。本文重点介绍匹配URL的正则表达式,感兴趣的朋友可以一起学习

  正则表达式描述了字符串匹配的一种模式,可用于检查字符串是否收录某个子字符串,替换匹配的子字符串,或者从字符串中提取满足某个条件的子字符串等等。

  正则表达式:

  

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

  使用说明:

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线