const regex = /Original-Recipient: [^;]+; (?<email>[^\n]+)/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Original-Recipient: [^;]+; (?<email>[^\\n]+)', '')
const str = `This is an automatically generated message from SendGrid.
We are sorry to tell you that your email was unable to be
delivered to one of its intended recipients.
If you require assistance with this, please contact SendGrid support.
Access denied - .102 listed by multiple RBL providers at the same time.
X-SendGrid-Sender: Paul Read paul@mydomain.com
Arrival-Date: Wed, 27 Mar 2024 18:26:16 +0000
Final-Recipient: rfc822; mickey@somedomain.com
Original-Recipient: rfc822; mickey@somedomain.com
Action: failed
Status: 159.183.224
Diagnostic-Code: 550 Access denied - 159.183.224.102 listed by multiple RBL providers at the same time.`;
// 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