在创建正则表达式以查找IP时使用\d {1,3} [英] Using \d{1,3} when creating regex to find IPs
问题描述
为什么人们在 \d {1,3}
中使用 {1,3}
IP与 grep
?例如:
Why would one use {1,3}
in \d{1,3}
when catching an IP with grep
? For example:
grep -Po 'inet addr:\K(?!127\.)\d{1,3}.\d{1,3}\.\d{1,3}\.\d{1,3}'
\K删除 inet addr:
和(?!127 \。)
,AFAIU,删除任何以127开头的地址(在这种情况下为环回),但 {1,3}
在<$之后c $ c> \d ?
\K removes inet addr:
, and (?!127\.)
, AFAIU, removes any address that starts with 127 (the loopback in that case), but what are the {1,3}
after \d
?
显然,我们不仅希望IP calsses从1开始,以2或3结束所以目的还不清楚。
Clearly, we don't only want IP calsses that starts in 1 and end with 2 or 3 so the purpose there is unclear to me.
注意: inet addr:
是<$ c $的一部分c> ifconfig Linux实用程序。
Note: inet addr:
is part of the ifconfig
Linux utility.
推荐答案
在写这个问题时,我想出了目的:它意味着在4个类的每个类中,我们将不超过3位数。
While writing the question I figured out the purpose: It means that in each class of the 4 classes, we will have not more than 3 digits.
确实在IPv4中(我不知道IPv6)我们只有3位数在每个班级。
Indeed in IPv4 (I don't know about IPv6) we have only 3 digits in each class.
这篇关于在创建正则表达式以查找IP时使用\d {1,3}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!