const regex = /((?:(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.){3}(?-1))/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('((?:(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)\\.){3}(?-1))', 'g')
const str = `Feb 8 21:48:20 server dhcpd: DHCPREQUEST for 10.232.10.241 (10.232.10.241) from 24:77:03:18:c9:d4 (kimxlt-03) via eth1
Feb 8 21:48:20 server dhcpd: DHCPACK on 10.232.10.76 to 24:77:03:18:c9:d4 (kimxlt-03) via eth1
Feb 8 21:48:24 server dhcpd: DHCPINFORM from 10.232.10.76 via eth1
Feb 8 21:48:24 server dhcpd: DHCPACK to 10.232.10.76 (24:77:03:18:c9:d4) via eth1
Feb 8 21:50:31 server dhcpd: DHCPINFORM from 10.232.10.92 via eth18 21:50:31 server dhcpd: DHCPACK to 10.232.10.92 (00:1c:c0:58:85:1b) via eth1
Feb 8 21:55:44 server dhcpd: DHCPINFORM from 10.232.10.92 via eth1
Feb 8 21:55:44 server dhcpd: DHCPACK to 10.232.10.92 (00:1c:c0:58:85:1b) via eth1
`;
// 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