简体   繁体   中英

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

The RegEx below only highlight specific Private IP addressing scheme:

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

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. My regex looks for IPs at the beginning of a line, immediately followed by a comma.

Note2: My regex does not really validate IPs. Eg 568.914.348.759 will be successfully returned.


For the new sample, try:

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

Test here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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