从给定的数组中获取Url

时间:2017-05-19 05:13:58

标签: regex get

{ "uploadUrl": "https://streetviewpublish.googleapis.com/media/user/11705162112362643904472027/photo/899853939832211842569886" }

从这里我只想要网址部分。我怎样才能获得网址

https://streetviewpublish.googleapis.com/media/user/11705162112362643904472027/photo/899853939832211842569886

1 个答案:

答案 0 :(得分:0)

如果您需要解析此字符串,则可以使用

https?:\/\/[^"]+

<强>解释

https? http https

开始

:\/\/后跟://

[^"]+任何字符,但双引号

您使用的是哪种语言?

使用JavaScript,您不会使用正则表达式而是使用JSON解析器

&#13;
&#13;
var str = '{ "uploadUrl": "https://streetviewpublish.googleapis.com/media/user/11705162112362643904472027/photo/899853939832211842569886" }';

var url = JSON.parse(str).uploadUrl;

console.log(url);
&#13;
&#13;
&#13;

或者,使用正则表达式

&#13;
&#13;
var str = '{ "uploadUrl": "https://streetviewpublish.googleapis.com/media/user/11705162112362643904472027/photo/899853939832211842569886" }';

var re = /https?:\/\/[^"]*/;
var url = str.match(re)[0];

console.log(url);
&#13;
&#13;
&#13;

Demo