我怎样才能得到这个字符串之后的所有内容

How do I get the everything after this string?

本文关键字:之后 字符串      更新时间:2023-12-21

我已经为我的url添加了一个值,所以现在看起来是这样的:

www.somepage.com&myValue=xxxxx

我的网址如下:

var url = document.URL;

我现在想要的是myValue=之后的一切。

我将使用什么正则表达式来实现这一点?

快速且肮脏:

//split the url at the "&"
  split_back=(url.split("&"));
//now split the url at the "="
  split_value=(split_back[1].split("="));

您需要的值在split_value[1]中。检查这个jsfiddle:http://jsfiddle.net/55rmkx76/2/

你可以这样做,

> var s = 'www.somepage.com&myValue=xxxxx';
undefined
> var re = /myValue=(.*)/;
undefined
> console.log(re.exec(s)[1])
xxxxx
undefined
> var s = 'www.somepage.com&myValue=xxxxx';
undefined
> s.split('myValue=')[1]
'xxxxx'