gpt4 book ai didi

RegEx IP 范围 A 类网络

转载 作者:行者123 更新时间:2023-12-04 01:03:28 25 4
gpt4 key购买 nike

我正在尝试过滤 IP 范围,它部分起作用,因为它还包括更高的范围。

我只需要从 10.0.0.110.20.0.254 的范围。

问题是它也匹配网络10.x.120.x

这是我使用的语法:

egrep '10.([0-9]{1,3}).([0-1]|[0-9]|20).([0-9]{1,3})'

例子:

echo '10.2.120.0' | egrep '10.([0-9]{1,3}).([0-1]|[0-9]|20).([0-9]{1,3})'

它还会打印不需要的 IP。我想将其限制为 10.x.20.x

最佳答案

根据您展示的示例,您能否尝试以下操作。

10\.(?:[0-9]|[0-1][0-9]?|20)\.0\.(?:25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[2-9][0-9]|1[1-9]|[1-9])

Online demo for above regex

使用 GNU grep 它将是:

grep -oP '10\.(?:[0-9]|[0-1][0-9]?|20)\.0\.(?:25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[2-9][0-9]|1[1-9]|[1-9])' Input_file

解释:

10\.(?:[0-9]|[0-1][0-9]?|20)\.0\.                         
##Matching 10 dot and range from 0 to 20 here, followed by 0. here.
(?:25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[2-9][0-9]|1[1-9]|[1-9])
##Matching from 1 to 254 range here in a non-capturing group.

关于RegEx IP 范围 A 类网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67318970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com