![](/img/trans.png)
[英]how to get the first and the last character of a string using a Regex and Javascript
[英]How to get first instance to last instance of a number in a string in javascript regex/ object error?
我在JSON.stringify
之后获得了字符串"{\\"id\\":\\"35112914\\"}"
。 我只想要数字35112914
或数字的第一个实例,即3
到最后一个即4
。 还有其他解决方法吗?
编辑:由于我得到一个奇怪的错误,我不得不进行分类。 在访问对象的属性时,我undefined
得到答案的答案,这使得该数字不可访问。 Stringify atleast显示数字。
编辑2:
我的代码写在node上,它向REST api发出curl请求。
curl.request(optionsRun, function (error, response) {
console.log(response);
setTimeout(function () {
ID = response ;
console.log(ID["id"]) ;
},2000) ;
}) ;
输出:
{"id":"35113281"}
undefined
您需要先解析对JS对象的响应,然后才能使用JS对象方法访问它:
curl.request(optionsRun, function (error, response) {
var ID = JSON.parse(response);
setTimeout(function () {
console.log(ID.id) ;
}, 2000);
});
此正则表达式将为您提供两个引号/\\"(\\d+)\\"/
之间的任何数字组合
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.