简体   繁体   English

用于匹配 IP 地址 class 的整个特定集合的正则表达式模式?

[英]The RegEx pattern for matching the entire specific sets of IP address class?

The RegEx below only highlight specific Private IP addressing scheme:下面的 RegEx 仅突出显示特定的 Private IP 寻址方案:

(?!^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]))

Like in this example https://regex101.com/r/tKKYx0/3 I need to update the code to only match the Public IP addresses list on the top.就像在这个例子中https://regex101.com/r/tKKYx0/3我需要更新代码以仅匹配顶部的公共 IP 地址列表。

A regex you can try is:您可以尝试的正则表达式是:

^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?=,)

Test here .在这里测试。

Note: I did not really understand how the first IPs are different from the rest of the IPs.注意:我不太明白第一个 IP 与 IP 的 rest 有何不同。 My regex looks for IPs at the beginning of a line, immediately followed by a comma.我的正则表达式在行首查找 IP,后跟逗号。

Note2: My regex does not really validate IPs.注意 2:我的正则表达式并没有真正验证 IP。 Eg 568.914.348.759 will be successfully returned.例如 568.914.348.759 将成功返回。


For the new sample, try:对于新示例,请尝试:

^(|(\S+.*?))(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})

Test here .在这里测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM