const regex = new RegExp('addr:([\\d.]+)', 'gm')
const str = `eth0
Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
inet addr:10.20.30.40 Bcast:10.20.30.254 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:66196498 errors:0 dropped:32831 overruns:0 frame:0
TX packets:61850152 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:41122659013 (41.1 GB) TX bytes:28800593238 (28.8 GB)
Interrupt:22 Memory:f6ae0000-f6b00000`;
// 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