Write a simple regular expression to match an IP address,
e-mail address, city-state-zipcode combination.

Answer Posted / jayakumar.b

sub validate_ip {

my $ip = shift;

if ( $ip =~ m/^([1-9]|1[0-9]{1,2}|2[0-4]\d|25[0-5])(\.([0-9]|1[0-9]{1,2}|2[0-4]\d|25[0-5])){3}$/ ) {
return 0;
} else {
return 1;
}
}

validate_ip("127.0.0.1");

Is This Answer Correct ?    4 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I sort a hash by the hash key?

564


Differentiate between arrays and list in perl.

532


What is confess function in perl?

535


What is the syntax used in Perl grep function?

581


How do I replace every TAB character in a file with a comma?

546






How do find the length of an array?

516


Explain string comparison operators in perl.

551


How to concatenate strings with perl?

470


Explain goto name?

511


what are the three groups involved in information sharing?

474


How to remove a directory in perl?

482


Differentiate between c++ and perl.

595


How to open and read data files with Perl

601


Explain '->' in perl?

500


How to connect to SQL server through Perl?

558