开发者

get specific part from url

开发者 https://www.devze.com 2023-01-01 16:48 出处:网络
my window.location is \"F:/html5/home.html\", from my location i need to get the file name like this \"home.开发者_JAVA百科html\", to do this, how to i use the regular expression command?

my window.location is "F:/html5/home.html", from my location i need to get the file name like this "home.开发者_JAVA百科html", to do this, how to i use the regular expression command?

any one help me?


This will do it

[^/]+$

It matches the substring of non-forward-slash characters towards the end of the string.

var s = "F:/html5/home.html";
//forwards slashes must be escaped in JavaScript regex as it is the delimiter
alert(s.match(/[^\/]+$/)[0]);


If you're flexible about not using regular expressions, I would do this:

var pathArr = new Array();
pathArr = window.location.split("/");
var file = pathArr[pathArr.length - 1];
0

精彩评论

暂无评论...
验证码 换一张
取 消