const regex = /(?<date>\d[\d:.]+)\W+(?<InPorts>\d+):\s*(?<OutPort>\d+)\W+G-MST:\s*(?<GMST>\w+)\W+guid=(?<Guid>[^"]+)"\W+(?<SourceIP>\d{1,3}(?:\.\d{1,3}){3})\W+(?<targetIP>\d{1,3}(?:\.\d{1,3}){3})\W+(?<SourceSpeed>\d+)\W+(?<TargetSpeed>\d+)\D+(?<AudioType>\d+)\D+(?<rsn>\d+)\W+(?<utc>\d[\d.:]*)\D+(?<pl>\d+)\D+(?<s>\d+)\D+(?<r>\d+)\D+(?<l>\d+)\D+(?<j>\d+)\D+(?<u>\d+)\D+(?<o>\d+)\D+(?<flags>0x\d+).*?:(?<sip>[^"]*)"\D+(?<vpn>\d+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<date>\\d[\\d:.]+)\\W+(?<InPorts>\\d+):\\s*(?<OutPort>\\d+)\\W+G-MST:\\s*(?<GMST>\\w+)\\W+guid=(?<Guid>[^"]+)"\\W+(?<SourceIP>\\d{1,3}(?:\\.\\d{1,3}){3})\\W+(?<targetIP>\\d{1,3}(?:\\.\\d{1,3}){3})\\W+(?<SourceSpeed>\\d+)\\W+(?<TargetSpeed>\\d+)\\D+(?<AudioType>\\d+)\\D+(?<rsn>\\d+)\\W+(?<utc>\\d[\\d.:]*)\\D+(?<pl>\\d+)\\D+(?<s>\\d+)\\D+(?<r>\\d+)\\D+(?<l>\\d+)\\D+(?<j>\\d+)\\D+(?<u>\\d+)\\D+(?<o>\\d+)\\D+(?<flags>0x\\d+).*?:(?<sip>[^"]*)"\\D+(?<vpn>\\d+)', 'gm')
const str = `08:07:46.914 ( 1708: 8624) G-MST: 400000EF " guid=00040000-73b2-5c7f-2295-00104941e7b0" ("10.10.60.3","10.10.29.251"),(10292, 59046),2(ULaw),rsn:1,12:05:15.623 (UTC),pl:20,(s:7525, r:7557, l:0),(j:0,u:27037,o:0) flgs:0x00000000 "sip:TGrp_5,p111@10.10.60.3:5441",vpn:0`;
// 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