import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "InvoiceItemID\":\"(\\d{6})";
final String string = "{\"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\"}";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html