JSFiddle - React, Tailwind, and code Playground
by brigand
HTML
<pre id="out"></pre>
JavaScript
console.log = (...args) => out.textContent += JSON.stringify(args) + '\n';
const match = '192.167.3/16'.match(/^(\d+\.)?(\d+\.)?(\d+\.)?(\d+?)?\/(\d+)$/);
if (match) {
let bytes = match.slice(1, -1).filter(Boolean);
let mask = match.slice().pop();
bytes = bytes.map(byte => byte ? parseInt(byte, 10) : null);
for (const byte of bytes) {
if (byte != null) {
console.log(byte, byte >= 0x00 && byte <= 0xff);
}
}
console.log({ mask });
}