Javascript Regex如何从url字符串获取参数。Jascript
你好,我有一个URL字符串:Javascript Regex如何从url字符串获取参数。Jascript,javascript,jquery,html,regex,Javascript,Jquery,Html,Regex,你好,我有一个URL字符串: 'http://www.hello.com/index.php?page=11' 我必须执行什么正则表达式才能获得页码 (\d+)[^\d]*$ 试试这个。抓拍。看演示 用于捕获一个或多个数字,这些数字正好出现在to?page= 您可以不使用任何regexp'http://www.hello.com/index.php?page=11“.split'page=”[1]没错!非常感谢。如果页面后面还有其他参数呢?不,没有。如果页面后面的参数包含数字,这也不起作用。
'http://www.hello.com/index.php?page=11'
我必须执行什么正则表达式才能获得页码
(\d+)[^\d]*$
试试这个。抓拍。看演示
用于捕获一个或多个数字,这些数字正好出现在to?page=
您可以不使用任何regexp'http://www.hello.com/index.php?page=11“.split'page=”[1]没错!非常感谢。如果页面后面还有其他参数呢?不,没有。如果页面后面的参数包含数字,这也不起作用。
> var s = 'http://www.hello.com/index.php?page=11'
undefined
> var re = /\?page=(\d+)/;
undefined
> console.log(re.exec(s)[1])
11
> var re = /\bpage=(\d+)/;
undefined
> console.log(re.exec(s)[1])
11