in reply to String Validation

Ok, you're probably getting lost with some of the delimiters and the anchors that are in there.

The ! are used to delimit the regex, instead of the standard /. This is often done to make the regex easier to read when certain meta characters need to be escaped in the regex.

In this particular case, they could have just as easily been the standard / making the regex look like this:

m/(^[a-z0-9]{4})$/

Does that look a bit more familiar to you?

The ^ and $ are there to anchor the regex. And there's a set of parenthesis to capture/cluster.

That should be enough to help you.

Some kind monk (sorry, I forget who) recently pointed out a nice CPAN module YAPE::Regex::Explain, that is quite useful:

#!/usr/bin/perl use warnings; use strict; use YAPE::Regex::Explain; my $re = qq[m!(^[a-z0-9]{4})$!]; my $yape = YAPE::Regex::Explain->new($re); print $yape->explain; __END__ The regular expression: (?-imsx:m!(^[a-z0-9]{4})) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- m! 'm!' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- [a-z0-9]{4} any character of: 'a' to 'z', '0' to '9' (4 times) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------