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)?)\b[\s+\w+]+[\w+:?]+)\s+(?<SourceIP>[\d+\.?]+)\s+(?P<EventID>%PIX-6-\d+):\s+(?P<EventMessage>Teardown UDP connection\s+\d+) for (?P<OutsideIP>.*?) to (?P<InternalIP>.*?)\s+duration\s+(?P<Duration>.*)\s+bytes(?P<Bytes>\s+\d+)/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)?)\\b[\\s+\\w+]+[\\w+:?]+)\\s+(?<SourceIP>[\\d+\\.?]+)\\s+(?P<EventID>%PIX-6-\\d+):\\s+(?P<EventMessage>Teardown UDP connection\\s+\\d+) for (?P<OutsideIP>.*?) to (?P<InternalIP>.*?)\\s+duration\\s+(?P<Duration>.*)\\s+bytes(?P<Bytes>\\s+\\d+)', 'g')
const str = `Jul 25 23:56:11 210.56.128.109 %PIX-6-302016: Teardown UDP connection 71944828 for Outside:192.168.20.21/22920 to Internal:osaka/137 duration 0:02:09 bytes 500`;
// 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