const regex = /\[(?<time>(?:[\d]+\:[\d]+:[\d]+)\s+(?:AM|PM))(?:\s+\|\s+\w+\s+(?<edited>(?:[\d]+\:[\d]+:[\d]+)\s+(?:AM|PM)))?\]\s+(?<author>\w+)\:\s+(?<message>[\w\s,.]+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\[(?<time>(?:[\\d]+\\:[\\d]+:[\\d]+)\\s+(?:AM|PM))(?:\\s+\\|\\s+\\w+\\s+(?<edited>(?:[\\d]+\\:[\\d]+:[\\d]+)\\s+(?:AM|PM)))?\\]\\s+(?<author>\\w+)\\:\\s+(?<message>[\\w\\s,.]+)', 'gm')
const str = `[9:14:51 AM] Jeff: If you could just do me a favoure and list all these concerns and in a mail and if you have any ideas that you might want to implement so that I can get everybodys notes.
[9:14:56 AM] Timmy: in terms of websites or domains or DNSs I have no clue about setup
[9:15:19 AM | Edited 9:15:25 AM] Jeff: That, I will get Sam and Frodo involved in
[9:16:01 AM] Jeff: I am stepping out quickly`;
// 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