const regex = /InvoiceItemID":"(\d{6})/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('InvoiceItemID":"(\\d{6})', '')
const str = `{"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"}`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions