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

What is confess function in perl?

545


Can you add two arrays together?

528


What are perl strings?

516


What is Perl?

561


Perl regular expressions are greedy" what does this mean?

505






Why Perl aliases are considered to be faster than references?

546


What does -> symbol indicates in Perl?

569


Explain the default scope of variables in perl?

517


Suppose an array contains @arraycontent=(‘ab’, ‘cd’, ‘ef’, ‘gh’). How to print all the contents of the given array?

602


How to do comment in perl?

577


Explain goto label, goto name, and goto expr?

557


What are the reasons that cookie server can’t handle multiple connections?

538


What is the tk module?

588


How to close a file in perl?

494


Explain substr function in perl?

541