本文介绍了Perl 正则表达式匹配 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了这段代码,但它不起作用.有人能指出问题吗?
I have written this code, but it does not work.Can someone point out the issue?
sub match_ip()
{
my $ip = "The IP address is 216.108.225.236:60099";
if($ip =~ /(d{1-3}.d{1-3}.d{1-3}.d{1-3}:d{1-5})/)
{
print "$1
";
}
}
我只想提取 IP 地址,不做任何验证.
I wanted to just extract the IP address, not do any validation.
推荐答案
将 {1-3}
更改为 {1,3}
与 {1 相同-5}
-> {1,5}
Change {1-3}
to {1,3}
same for {1-5}
-> {1,5}
这篇关于Perl 正则表达式匹配 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!