const regex = /(?P<Timestamp>\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s+\d+\s+\d+:\d+:\d+)\b\s+(?P<FW_ip_addr>\d+\.\d+\.\d+\.\d+)\s+(?P<Event_id>%\w+-\d+-\d+):\s+(?P<Event_message>\d+ in use, \d+ most used)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?P<Timestamp>\\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\\s+\\d+\\s+\\d+:\\d+:\\d+)\\b\\s+(?P<FW_ip_addr>\\d+\\.\\d+\\.\\d+\\.\\d+)\\s+(?P<Event_id>%\\w+-\\d+-\\d+):\\s+(?P<Event_message>\\d+ in use, \\d+ most used)', 'g')
const str = `Jul 25 23:57:12 210.56.128.109 %PIX-6-302010: 851 in use, 7079 most used`;
// 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