-2

I'm trying to get "10086" (the 'todId' next to "PENDING") out of the following text:

... [{"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" ...

Please note, there is more characters before and after the above text.

How can I extract it? What can be the correct regular expression?

Thanks in advance! --Ishti

UPDATE: Here is the complete text:

{"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"}}
Ishtiaque Hussain
  • 383
  • 1
  • 5
  • 20
  • How can you isolate anything, when all is comma separated, quoted/non-quoted values. Can't be done like you think. –  Jul 06 '15 at 18:56
  • That's why I asked in StackOverflow to see if some expert can help me! This is a JSON text. I have found out a way to find the last 'todId' from the text. Using Regular Expression Extractor in JMeter we can do it. [Here](http://stackoverflow.com/questions/26648257/how-can-i-get-the-last-match-in-regular-extracor-expression-in-jmeter) is a link for that. But the 'todId' I'm looking should be the one next to 'PENDING'. It's not always the the last one. – Ishtiaque Hussain Jul 06 '15 at 19:28
  • 1
    Is this "todId":(\d+),"torId":(\d+),"t":"VAC","c":"N","st":"PENDING" working for you? if not paste all the text you have, probably then a better solution will be available. – Nachiket Kate Jul 07 '15 at 05:23
  • @NachiketKate With a quick check, it's working. I'll check this in details first thing tomorrow morning and let you know. Thank you very much!! – Ishtiaque Hussain Jul 07 '15 at 07:07
  • I didn't get a chance to look at it today. But I'm confident this is the answer. Do you know how I can mark it as the answer? – Ishtiaque Hussain Jul 07 '15 at 20:55

2 Answers2

0

Use the following regex:

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

It will match what you are looking for. The captured group will always contain the nearest 'todId' next to the text "PENDING"

Here is the demo link for you to see the regex in action.

Vaibhav Gupta
  • 381
  • 3
  • 11
  • For me, this is selecting the outer match, starting from the first 'todId' (i.e., the first example text in my question) - not the nearest 'todId' next to the text 'PENDING'. – Ishtiaque Hussain Jul 07 '15 at 07:12
  • Yes it is indeed matching the first 'todId', but if you see in the demo link i have published, it is actually matching the whole string from first 'todId' till the text 'PENDING' and is capturing the 'todId' which is closest to 'PENDING'. You can see the matches on the right hand side in the demo link. – Vaibhav Gupta Jul 07 '15 at 10:58
-1

Does this one helps?

(?:todId)+.+\"todId\":([0-9]+).+PENDING
Mindastic
  • 4,023
  • 3
  • 19
  • 20