
mhassan
Novice
Jan 21, 2010, 9:31 AM
Post #1 of 3
(1710 views)
|
|
Validate string
|
Can't Post
|
|
Hi, I want to check if the $mystring variable is less than or equal to 3 characters using regex. If variable string is less than or equal to 3 then print "your string is less than or equal to 3 characters". Below is my test code.
#!/usr/bin/perl -w use strict; my $mystring = "lsdkajsssssssssssssssssssssfkljadskljfkldsaj"; my $regex = ".{0,3}"; if ($mystring =~ m/.{0,3}/){ print "your string is less than or equal to 3 characters\n"; } exit; This code prints "your string is less than or equal to 3 characters" even though i don't want the it to since $mystring is larger than 3 characters. I don't know anything about regex. Any help?
|