Reputation: 3615
I am trying to use regex grab the first occurrence of InvoiceItemID
in the JSON data shown below:
This is the regex string that I current have:
\d{6}(?=","Location":"ARN:190801210003100)
The current regex string returns two matches, but I am only interested in the first occurrence/match. I understand that what I need to do is make the regex non-greedy, which usually involves using something like this: (.*?)
but I do not know where to implement this non-greedy code. Any help would be appreciated. Thanks.
Here is some raw data if needed for testing purposes:
{"ClientRef":"","Date":"2015-09-29 10:02:51 AM","InvoiceID":"451393","InvoiceItemID":"495340","Location":"ARN:193602013349538<br\/>16 LEIGHLAND DR , CITY OF MARKHAM, ON, L3R 7R4","ReportID":"268172,","Type":"ICI Commercial \/ Industrial Report"},{"ClientRef":"","Date":"2015-09-28 8:39:41 PM","InvoiceID":"451035","InvoiceItemID":"494939","Location":"ARN:190801210003100<br\/>2250 SHEPPARD AVE W, CITY OF TORONTO, ON, M9M 1L7","ReportID":"267810,","Type":"Basic Report"},{"ClientRef":"","Date":"2015-09-28 8:39:20 PM","InvoiceID":"451034","InvoiceItemID":"494938","Location":"ARN:190801210003100<br\/>2250 SHEPPARD AVE W, CITY OF TORONTO, ON, M9M 1L7","ReportID":"267809,","Type":"ICI Commercial \/ Industrial Report"},{"ClientRef":"","Date":"2015-09-28 2:59:03 PM","InvoiceID":"450515","InvoiceItemID":"494348","Location":"ARN:240201011110900<br\/>26-34 PLAINS RD E, BURLINGTON CITY, ON, L7T 2B9","ReportID":"267272,","Type":"ICI Commercial \/ Industrial Report"}
Upvotes: 0
Views: 253
Reputation: 4568
Your regex is not the way to go. You can see how you fail to match all here. Here is a demo of it working with this regex:
InvoiceItemID":"(\d{6})
Upvotes: 1