JSON键值的正则表达式 [英] regex for json key value

查看:264
本文介绍了JSON键值的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是regex的新手,我正尝试在以下json中的l_fix之后获取值:

Hi i'm new to regex and i'm trying to grab the value after l_fix in the following json:

{ "id": "626307" ,"t" : ".INX" ,"e" : "INDEXSP" ,"l" : "2,050.59" ,"l_fix" : "2050.59" ,"l_cur" : "2,050.59" ,"s": "0" ,"ltt":"3:08PM EST" ,"lt" : "Nov 17, 3:08PM EST" ,"lt_dts" : "2015-11-17T15:08:33Z" ,"c" : "-2.60" ,"c_fix" : "-2.60" ,"cp" : "-0.13" ,"cp_fix" : "-0.13" ,"ccol" : "chr" ,"pcls_fix" : "2053.19" }

现在我正在使用\d[,](?:\d*\.)?\d+ 但是,这似乎有点蛮力,我相信它可以做得更好.

right now i'm using \d[,](?:\d*\.)?\d+ however this seems a bit brute force and i'm sure it can be done better.

推荐答案

正则表达式似乎不是您所需要的,但是,如果要使用正则表达式,它可能是这样的:"l_fix"\s*:\s*"(.+?)".然后,在第一个组中,您将拥有所要寻找的价值.

A regex doesn't seem to be what you need, however if you want to do it with a regex it could be this one: "l_fix"\s*:\s*"(.+?)". Then, in the first group you'll have the value you are looking for.

在此处查看其工作

此外,请参阅有关SO的正则表达式组的这篇SO帖子.

这篇关于JSON键值的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆