Perl正则表达式以匹配IP地址 [英] Perl regular expression to match an IP address

查看:1199
本文介绍了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\n";
  }
}

编辑:
我想提取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地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆