11cb0ef41Sopenharmony_ciconst word = '[a-fA-F\\d:]'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst boundry = options => options && options.includeBoundaries 41cb0ef41Sopenharmony_ci ? `(?:(?<=\\s|^)(?=${word})|(?<=${word})(?=\\s|$))` 51cb0ef41Sopenharmony_ci : ''; 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst v4 = '(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}'; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst v6segment = '[a-fA-F\\d]{1,4}'; 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst v6 = ` 121cb0ef41Sopenharmony_ci(?: 131cb0ef41Sopenharmony_ci(?:${v6segment}:){7}(?:${v6segment}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8 141cb0ef41Sopenharmony_ci(?:${v6segment}:){6}(?:${v4}|:${v6segment}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4 151cb0ef41Sopenharmony_ci(?:${v6segment}:){5}(?::${v4}|(?::${v6segment}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4 161cb0ef41Sopenharmony_ci(?:${v6segment}:){4}(?:(?::${v6segment}){0,1}:${v4}|(?::${v6segment}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4 171cb0ef41Sopenharmony_ci(?:${v6segment}:){3}(?:(?::${v6segment}){0,2}:${v4}|(?::${v6segment}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4 181cb0ef41Sopenharmony_ci(?:${v6segment}:){2}(?:(?::${v6segment}){0,3}:${v4}|(?::${v6segment}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4 191cb0ef41Sopenharmony_ci(?:${v6segment}:){1}(?:(?::${v6segment}){0,4}:${v4}|(?::${v6segment}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4 201cb0ef41Sopenharmony_ci(?::(?:(?::${v6segment}){0,5}:${v4}|(?::${v6segment}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4 211cb0ef41Sopenharmony_ci)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1 221cb0ef41Sopenharmony_ci`.replace(/\s*\/\/.*$/gm, '').replace(/\n/g, '').trim(); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci// Pre-compile only the exact regexes because adding a global flag make regexes stateful 251cb0ef41Sopenharmony_ciconst v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`); 261cb0ef41Sopenharmony_ciconst v4exact = new RegExp(`^${v4}$`); 271cb0ef41Sopenharmony_ciconst v6exact = new RegExp(`^${v6}$`); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciconst ipRegex = options => options && options.exact 301cb0ef41Sopenharmony_ci ? v46Exact 311cb0ef41Sopenharmony_ci : new RegExp(`(?:${boundry(options)}${v4}${boundry(options)})|(?:${boundry(options)}${v6}${boundry(options)})`, 'g'); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ciipRegex.v4 = options => options && options.exact ? v4exact : new RegExp(`${boundry(options)}${v4}${boundry(options)}`, 'g'); 341cb0ef41Sopenharmony_ciipRegex.v6 = options => options && options.exact ? v6exact : new RegExp(`${boundry(options)}${v6}${boundry(options)}`, 'g'); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ciexport default ipRegex; 37