const regex = /\b([KNW][A-Z]?|A[A-L])[0-9][A-Z]{1,3}\b(?:-@)?/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\b([KNW][A-Z]?|A[A-L])[0-9][A-Z]{1,3}\\b(?:-@)?', 'g')
const str = `\$pattern .= ""; //N9URK, W1AW, W1W
\$pattern .= ""; //WB6NOA, AD4HZ, WA1W
IW1GJR
K, N, W, AA-AL, KA-KZ, NA-NZ or WA-WZ
All of these returning false with RegEx.test in JavaScript:
pen.js:23 JA1HOX
pen.js:23 IQ6WJ
pen.js:23 CE2AWW
pen.js:23 SK2AT
pen.js:23 IW1EVR
pen.js:23 9A3LE-@
pen.js:23 EA5IGO
pen.js:23 SK2AT
pen.js:23 W6BOI <-------
pen.js:23 IZ3ZUS
pen.js:23 YO3YX
pen.js:23 ON4LDP
pen.js:23 BG3UPA
pen.js:23 FW5JJ
pen.js:23 RM4D-@
pen.js:23 RN3QTS
pen.js:23 OH6PA
pen.js:23 W3LPL <-------
pen.js:23 SK2AT
pen.js:23 K2CYS
pen.js:23 EW4DW
pen.js:23 EC1DJ
pen.js:23 R3NA
pen.js:23 JA6GGD
pen.js:23 N3YZ-@
pen.js:23 K0BX
pen.js:23 WA2VUY-@
pen.js:23 IZ3WXG
pen.js:23 DD3EU-@
pen.js:23 UR4UWY-@
pen.js:23 ON4LDP
pen.js:23 K5VJZ
pen.js:23 RZ3LA-@
pen.js:23 OE9NFI
pen.js:23 OH1F
pen.js:23 K2CYS
pen.js:23 HA0DU
pen.js:23 EB8CRM
pen.js:23 TA2OTT-@
pen.js:23 EA1AST
pen.js:23 N0TR
pen.js:23 RK6FV
pen.js:23 YU7AF
pen.js:23 F0FVK
pen.js:23 FW5JJ
pen.js:23 R2ZA-@
pen.js:23 G0LGS
pen.js:23 5B4AIZ-@
pen.js:23 RZ3LA-@
7275 N4N 2015-10-06T19:32:38 military convoy SE United States N8POG
7183 LZ130SAK 2015-10-06T19:30:04 CQ cq SES AWARD Bulgaria DL2AMM
7275 N4N 2015-10-06T19:29:03 Bankhead Convoy Host Station United States KA4WJR-@
18163 CN8NOA 2015-10-06T19:28:22 your dear friend NORI Morocco W4QNW
14268 S79SP 2015-10-06T19:28:16 Listening up Seychelles WA3ZHG-@
1846 HG8ITU 2015-10-06T19:27:18 CQ RTTY RTTY Hungary HA8BT
14260 W1AW 2015-10-06T19:26:06 tnx United States IW1GJR
14268 S79SP 2015-10-06T19:25:53 59 EPA by mumbers up10 Seychelles W3RJW`;
// 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