const regex = new RegExp('^(?P<call>.+)>(?P<dest>.+),(?P<q>q.{2}),(?P<via>.+):@(?P<time>.+z)(?P<place>.+)_(?P<wdir>.{3})/(?P<wspd>.{3})g(?P<guts>.{3})t(?P<temp>.{3})r(?P<rain1>.{3})p(?P<rain24>.{3})P(?P<rainMn>.{3})(h(?P<hum>.{2})b(?P<press>.{5})|b(?P<press1>.{5})h(?P<hum1>.{2})).(?P<add>.+)$', 'mg')
const str = `FW4018>APRS,TCPXX*,qAX,CWOP-6:@130940z4503.87N/03856.27E_005/001g004t030r000p000P000b10294h97.weewx-3.8.0-WS1
NR6G-5>APRS,NR6G-4,WIDE1*,qAR,KI6PIO-7:@140933z3517.33N/11851.40W_117/002g007t054r000p000P000h43b10263.DsVP
VE3GOP>APRS,TCPIP*,qAC,T2NALA:@084045z4333.72N/07945.94W_32767/255g000t...r000p001P000h69b10260wDvs
DM2KB-13>APMI01-13,TCPIP*,qAS,DM2KB:@140940z5137.03N/00704.59E_154/002g007t052r000p001P001h83b10281L241WX3in1 & Davis Vantage Pro2
WB2JSH>APRS,TCPIP*,qAC,EIGHTH:@140940z4032.40N/10447.03W_036/000g...t023r...p...P000h86b10289L000.DsVP
SR8WXD>AKLPRZ,TCPIP*,qAC,T2KRAKOW:!4934.33N/02139.07E_323/011g019t032r...p...P...b.....
W4VA-10>APDW15,WIDE1-1,WIDE2-1,qAR,KG4GIY:!3844.04NR07750.16W&PHG3660Viewtree Mtn, Warrenton, VA FM18br`;
// 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