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 ----------------------------------------------------------------------

In reply to Re: String Validation by chakram88
in thread String Validation by Trihedralguy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.