鍍金池/ 問答/PHP  HTML/ 如何找到網(wǎng)址中的固定字段

如何找到網(wǎng)址中的固定字段

clipboard.png

我需要找到這網(wǎng)址的index.html前面的search這幾個(gè)字

回答
編輯回答
獨(dú)特范

location.search.split('/')[1]

2018年2月27日 01:53
編輯回答
疚幼
var str = 'http://a.com/b/c.php?s=/Search/index.html';
str.match(/(?!\?s=\/)\w+?(?=\/index\.html)/g);

// ["Search"]

//如果地址是這樣的:
var str = 'http://a.com/b/c.php?s=/Search/a/b/index.html';
str.match(/(?!\?s=\/)[\w\/]+?(?=\/index\.html)/gi);

//["/Search/a/b"]
2017年10月11日 10:05