如何从网址中提取“搜索字词”?

ben*_*ben 2 javascript

如何从以下网址提取“测试”?

http://www.example.com/index.php?q=test&=Go

我找到了一个提取路径(window.location.pathname)的脚本,但是我找不到或弄清楚如何提取或分割URL。

-本

Jam*_*mes 5

var m = window.location.search.match(/q=([^&]*)/);

if (m) { 
    alert(m[1]); // => alerts "test"
} 
Run Code Online (Sandbox Code Playgroud)