const regex = /Reg: Email:/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Reg: Email:', 'gm')
const str = `Hi,
Congrats, your offer on a Ford Ka for the price of £2,000.00, was the winning offer!
Car Details
Ford Ka
Model: Ford Ka
Reg: LN61XVW
Fee: £229.0
Distance: 32 miles
Mileage: 28709
Car age: 13
Colour: BLACK
See customer details
You’ll need to find a time that’s right for both parties so you can inspect the vehicle and make sure it looks as good as advertised.
Ask us to collect for you or pick it up yourself and arrange payment with the seller.
Customer Contact Details
Name: Donna Irwin
Phone: +447884015643
Email: donna.irwin@btinternet.com
Postcode: AL1 2ET
Follow the link below to get in touch and exchange details.
Contact the seller here
Use the help link below if you have any questions.
Happy Hunting,
The Carwow Team`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// 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