const regex = /\b(?!0\.)(?!10\.)(?!100\.6[4-9]\.)(?!100\.[7-9]\d\.)(?!100\.1[0-1]\d\.)(?!100\.12[0-7]\.)(?!127\.)(?!169\.254\.)(?!172\.1[6-9]\.)(?!172\.2[0-9]\.)(?!172\.3[0-1]\.)(?!192\.0\.0\.)(?!192\.0\.2\.)(?!192\.88\.99\.)(?!192\.168\.)(?!198\.1[8-9]\.)(?!198\.51\.100\.)(?!203.0\.113\.)(?!22[4-9]\.)(?!23[0-9]\.)(?!24[0-9]\.)(?!25[0-5]\.)(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\b/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\b(?!0\\.)(?!10\\.)(?!100\\.6[4-9]\\.)(?!100\\.[7-9]\\d\\.)(?!100\\.1[0-1]\\d\\.)(?!100\\.12[0-7]\\.)(?!127\\.)(?!169\\.254\\.)(?!172\\.1[6-9]\\.)(?!172\\.2[0-9]\\.)(?!172\\.3[0-1]\\.)(?!192\\.0\\.0\\.)(?!192\\.0\\.2\\.)(?!192\\.88\\.99\\.)(?!192\\.168\\.)(?!198\\.1[8-9]\\.)(?!198\\.51\\.100\\.)(?!203.0\\.113\\.)(?!22[4-9]\\.)(?!23[0-9]\\.)(?!24[0-9]\\.)(?!25[0-5]\\.)(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\\b', 'gm')
const str = `62.171.129.137
46.140.17.46
142.79.230.133
92.42.45.118
45.79.22.6
192.248.32.211
121.36.165.78
52.14.0.168
52.151.57.51
165.232.185.3
52.226.67.129
`;
// 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