2015-10-04 63 views
0

我想使用正則表達式搶在JSON數據InvoiceItemID中第一次出現如下圖所示: enter image description here 這是正則表達式的字符串,我目前有: \d{6}(?=","Location":"ARN:190801210003100) 目前正則表達式字符串返回兩個匹配,但我只對第一個匹配項有興趣。我明白,我需要做的是使正則表達式非貪婪,通常涉及使用這樣的東西:(.*?)但我不知道在哪裏實現這個非貪婪的代碼。任何幫助,將不勝感激。謝謝。正則表達式的非貪婪範圍的數字

下面是一些原始數據,如果需要測試目的:

{"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"} 

回答

1

你的正則表達式是不是要走的路。你可以看到你如何不符合所有here。這是一個demo它與這個正則表達式:

InvoiceItemID":"(\d{6})