const regex = /Author:\s*(?<name>.+)\s+Date:\s*(?<date>.+)\s+(?<message>(?:(?!commit .{40}).)+)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Author:\\s*(?<name>.+)\\s+Date:\\s*(?<date>.+)\\s+(?<message>(?:(?!commit .{40}).)+)', 'g')
const str = `commit 11ae9c97409fb349e2bfa50ed65bd23ec6dbca70
Author: Fabien Potencier <fabien.potencier@gmail.com>
Date: Wed Jul 11 19:51:30 2012 +0200
updated VERSION for 2.0.16
commit 6e14d67cb23439d6700f494e29e809811edeeade
Author: Fabien Potencier <fabien.potencier@gmail.com>
Date: Wed Jul 11 19:50:55 2012 +0200
update CONTRIBUTORS for 2.0.16
commit 0341492ed566fca8df556573b9664f691c5dff3d
Author: Fabien Potencier <fabien.potencier@gmail.com>
Date: Wed Jul 11 19:48:12 2012 +0200
updated CHANGELOG for 2.0.16
commit b18f6f557b5db1e2e6d2c2c0494e0564b91f438d
Author: Fabien Potencier <fabien.potencier@gmail.com>
Date: Tue Jul 10 15:28:02 2012 +0200
[Console] fixed wrong phpdoc (closes #4394)
Match This line`;
// 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