什么正则表达式或功能需要从json响应中获取数据

时间:2017-10-05 11:27:00

标签: javascript jquery regex

$.ajax({
    url: link,   //https://www.linkedin.com/company/666511/
    type: 'GET',
    success: function (data) {
console.log(data)

//response comes in 2000 lines  
here is the sample short response

["Web Development","Professional Training","Apprenticeship","Nonprofit"]
,
"companyPageUrl":"http://www.thedifferenceengine.io"

//i only want this link to return
http://www.thedifferenceengine.io
}
});
  

我不明白正则表达式或jquery需要什么,或者我如何删除此&引用并获取companypageurl

2 个答案:

答案 0 :(得分:2)

你可以使用正则表达式

/http:[^;]+/

let str = '["Web Development","Professional Training","Apprenticeship","Nonprofit"],"companyPageUrl":"http://www.thedifferenceengine.io"'

console.log(str.match(/http:[^;]+/));

答案 1 :(得分:0)

 var decode ='["Web Development","Professional Training","Apprenticeship","Nonprofit"],"companyPageUrl":"http://www.thedifferenceengine.io"';

 alert($("<div/>").html(decode).text());