Regex – What regex can I use to match any valid IP-address represented in dot-decimal notation

ip addressperlregex

What regex can I use to match any valid IP-address represented in dot-decimal notation?

Best Answer

if($ip=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/ &&(($1<=255  && $2<=255 && $3<=255  &&$4<=255 )))
     {
         print "valid\n";
     }
     else
     {
         print "Invalid\n";
     }