如何找到网址中的固定字段

clipboard.png

我需要找到这网址的index.html前面的search这几个字

阅读 2.1k
2 个回答
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"]

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题