const regex = /<REMITReceipt(.|\n)*?<errorCount>0(.|\n)*?\/REMITReceipt>/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<REMITReceipt(.|\\n)*?<errorCount>0(.|\\n)*?\\\/REMITReceipt>', '')
const str = `
=== Receipt_20150922_REMITTable1_V1_A0000668C.SI_1.xml.asc
<REMITReceipt xmlns="http://www.acer.europa.eu/REMIT/REMITReceiptSchema_V1.xsd">
<receiptTimestamp>2015-09-22T14:25:04.009+02:00</receiptTimestamp>
<rrmId>
<acer>A0000668C.SI</acer>
</rrmId>
<receiptType>validation</receiptType>
<validationReceipt>
<reportedFilename>20150922_REMITTable1_V1_A0000668C.SI_1.xml.asc.pgp</reportedFilename>
<reportedFileChecksum>6445BEC781F4000C7F16F8685103B2D2D4DC500B</reportedFileChecksum>
<errorCount>0</errorCount>
<globalReceiptItem>
<logicalRecordIdentifier>FWG_L_Sep_15</logicalRecordIdentifier>
<logicalRecordType>CONTRACT</logicalRecordType>
<status>Accepted</status>
</globalReceiptItem>
</validationReceipt>
</REMITReceipt>
=== Receipt_20150922_REMITTable1_V1_A0000668C.SI_10.xml.asc
<REMITReceipt xmlns="http://www.acer.europa.eu/REMIT/REMITReceiptSchema_V1.xsd">
<receiptTimestamp>2015-09-24T09:35:07.530+02:00</receiptTimestamp>
<rrmId>
<acer>A0000668C.SI</acer>
</rrmId>
<receiptType>validation</receiptType>
<validationReceipt>
<reportedFilename>20150922_REMITTable1_V1_A0000668C.SI_10.xml.asc.pgp</reportedFilename>
<reportedFileChecksum>13F5F5D46DFC659380AD1A7982CC2F05E7E66D5E</reportedFileChecksum>
<errorCount>0</errorCount>
<globalReceiptItem>
<logicalRecordIdentifier>4</logicalRecordIdentifier>
<logicalRecordType>TRADE</logicalRecordType>
<status>Accepted</status>
<logicalRecordTimestamp>2015-07-14T13:12:16.223+02:00</logicalRecordTimestamp>
<logicalRecordChecksum>F6A488630A39390BE48420AFFD40ED7C82D20309</logicalRecordChecksum>
</globalReceiptItem>
<globalReceiptItem>
<logicalRecordIdentifier>3</logicalRecordIdentifier>
<logicalRecordType>TRADE</logicalRecordType>
<status>Accepted</status>
<logicalRecordTimestamp>2015-07-14T13:12:16.223+02:00</logicalRecordTimestamp>
<logicalRecordChecksum>026F539B94346186078BA906DE2F5A9F8B3E7F6E</logicalRecordChecksum>
</globalReceiptItem>
<globalReceiptItem>
<logicalRecordIdentifier>2</logicalRecordIdentifier>
<logicalRecordType>TRADE</logicalRecordType>
<status>Accepted</status>
<logicalRecordTimestamp>2015-07-14T08:46:40.513+02:00</logicalRecordTimestamp>
<logicalRecordChecksum>0F8253A2A3C55520E4D63959E77286CA1E95622B</logicalRecordChecksum>
</globalReceiptItem>
<globalReceiptItem>
<logicalRecordIdentifier>1</logicalRecordIdentifier>
<logicalRecordType>TRADE</logicalRecordType>
<status>Accepted</status>
<logicalRecordTimestamp>2015-07-14T08:46:37.223+02:00</logicalRecordTimestamp>
<logicalRecordChecksum>198B018687C9D97CD3EECFBACA7EA9F196B5B80F</logicalRecordChecksum>
</globalReceiptItem>
</validationReceipt>
</REMITReceipt>
=!== Receipt_20150922_REMITTable1_V1_A0000668C.SI_100.xml.asc `;
// 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