繁体   English   中英

如何获得此字符串之后的所有内容?

[英]How do I get the everything after this string?

我已经在网址中附加了一个值,所以现在看起来像这样:

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'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM