佚名通过本文主要向大家介绍了目录正则表达式,正则表达式,正则表达式提取数字,数字 正则表达式,html正则表达式等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题:匹配链接目录部分的正则表达式应该如何写?
描述:
解决方案1:
描述:
匹配链接目录部分的正则表达式应该如何写?
http://localhost/wp-content/plugins/campus-grouper/
有这么一个链接,我需要通过正则表达式匹配得到结果:
wp-content/plugins/campus-grouper/
请问应该怎么写?
解决方案1:
(?<=(http|https)://.+?/).+
解决方案2:var reg = /^http:\/\/[^\/]+\/(.*)$/
var s = "http://localhost/wp-content/plugins/campus-grouper/";
reg.test(s); //true
var ret = s.match(reg); // ["http://localhost/wp-content/plugins/campus-grouper/", "wp-content/plugins/campus-grouper/"]
console.log(ret[1]);