Newbie Perl question...
If you wanted to match for 2-5 x's, followed by a z, this pattern match should work...
/x{3,5}z/
If I enter less than 3 x's, it returns false as it should, but if I enter more than 5 x's, it returns true, which is wrong.
I'm using a script that tests different regular expressions...
print "Enter a string: ";
chomp($string = <STDIN>);
print "Enter a pattern: ";
chomp($pattern = <STDIN>);
if ($string =~ /$pattern/) { print "True\n"; }
else { print "False\n"; }
Also, the ? character is supposed to match zero or one instance of the character before it. If I enter ddd as the string, and /d?/ as the pattern, it still returns true. I thought that it would only return true if there were either zero or one instance of the letter d
Thanks,
ChrisP
RHCE, LPIC-1, CCNA, CNE, MCSE, +10 others
If you wanted to match for 2-5 x's, followed by a z, this pattern match should work...
/x{3,5}z/
If I enter less than 3 x's, it returns false as it should, but if I enter more than 5 x's, it returns true, which is wrong.
I'm using a script that tests different regular expressions...
print "Enter a string: ";
chomp($string = <STDIN>);
print "Enter a pattern: ";
chomp($pattern = <STDIN>);
if ($string =~ /$pattern/) { print "True\n"; }
else { print "False\n"; }
Also, the ? character is supposed to match zero or one instance of the character before it. If I enter ddd as the string, and /d?/ as the pattern, it still returns true. I thought that it would only return true if there were either zero or one instance of the letter d
Thanks,
ChrisP
RHCE, LPIC-1, CCNA, CNE, MCSE, +10 others