为了账号安全,请及时绑定邮箱和手机立即绑定

求一个js正则表达式

求一个js正则表达式

慕码人8056858 2019-04-16 20:26:00
检索一个json字符串;格式:varjson='[{"i":"t2","n":"xx","x":"12678","y":"10456","c":"","m":3},{"i":"t3","n":"xx","x":"13678","y":"11456","c":"","m":3},{"i":"t4","n":"xx","x":"18456","y":"13456","c":"","m":3}]';//条件11000
查看完整描述

2 回答

?
慕后森

TA贡献1802条经验 获得超5个赞

试试json.match(/\{[^{]+?\"x\":\"1[12][0-9]{3}\",\"y\":\"1[12][0-9]{3}\",[^}]+?\}/g)?看看我有没有写错
/\{[^{]+?//排除{,使用惰性匹配
\"x\":\"1[12][0-9]{3}\",//只匹配x从11000到12999的内容
\"y\":\"1[12][0-9]{3}\",[^}]+?\}/g//作用于全局
                            
查看完整回答
反对 回复 2019-04-16
?
蝴蝶不菲

TA贡献1810条经验 获得超4个赞

没必要用正则啊。js处理json最合适不过了。
varjson='[{"i":"t2","n":"xx","x":"12678","y":"10456","c":"","m":3},{"i":"t3","n":"xx","x":"13678","y":"11456","c":"","m":3},{"i":"t4","n":"xx","x":"18456","y":"13456","c":"","m":3}]';
//条件11000
vardata=JSON.parse(json);
varresult=[];
data.forEach(function(item){
if(item.x>11000&&item.x<13000&&item.y>11000&&item.y<13000){
console.log(item);
result.push(item);
}
});
                            
查看完整回答
反对 回复 2019-04-16
  • 2 回答
  • 0 关注
  • 379 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信