in reply to Re^6: how should i test whether a string contains between 6 and 20 letters and numbers
in thread how should i test whether a string contains between 6 and 20 letters and numbers

Finally I understand your issue, and you are quite right. My regex using $ ignores a single trailing new line character. Vis:

use strict; use warnings; my @strs = ("abcdefghijklm\n\n", "abcdefghijklm\n"); for (@strs) { if (/^[a-zA-Z0-9]{6,20}$/) { print "Success: >$_<\n"; } else { print "Invalid string: >$_<\n"; } }

Prints:

Invalid string: >abcdefghijklm < Success: >abcdefghijklm <

If your first reply had said:

Your solution ignores a trailing newline. Try it with this string: $_ = "abcdefghijklm\n";

I'd have understood your concern straight off. If there was anyone else remaining confused I hope the issue is now clear and that they have learned something, as I have.


DWIM is Perl's answer to Gödel
  • Comment on Re^7: how should i test whether a string contains between 6 and 20 letters and numbers
  • Select or Download Code