如何使用正则表达式在更广泛的外部匹配中提取内部匹配?

时间:2015-07-06 18:38:43

标签: regex jmeter

我试图从以下文字中获得“10086”(“待命”旁边的“todId”):

... [{"todId":10083,"torId":10013,"t":"VAC","c":"N","st":"APPROVED","s":null,"e":null,"cr":"2015-07-06T13:12:02","r":null,"sc":"Test","ac":null}],null,null,[{"todId":10086,"torId":10016,"t":"VAC","c":"N","st":"PENDING" ...

请注意,上述文字前后有更多字符。

我该如何提取它?什么是正确的正则表达式?

提前致谢! --Ishti

更新:这是完整的文字:

{"rows":{"904218":[null,null,null,null,null,null,[{"todId":10083,"torId":10013,"t":"VAC","c":"N","st":"APPROVED","s":null,"e":null,"cr":"2015-07-06T13:12:02","r":null,"sc":"Test","ac":null}],null,null,[{"todId":10086,"torId":10016,"t":"VAC","c":"N","st":"PENDING","s":null,"e":null,"cr":"2015-07-06T13:50:05","r":null,"sc":"Test","ac":null}],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]},"holidays":{},"l10n":{"TOP_APPROVED":"Approved","TOFFTYP_VAC":"VAC","TOP_PENDING":"Requested"}}

2 个答案:

答案 0 :(得分:0)

使用以下正则表达式:

(?:(?:"todId"\:([0-9]+),.+?)+?PENDING.+?)+?

它符合您的要求。捕获的组将始终包含最近的' todId'在文本旁边" PENDING"

以下是demo链接,供您查看正在使用的正则表达式。

答案 1 :(得分:-1)

这个有帮助吗?

(?:todId)+.+\"todId\":([0-9]+).+PENDING