I, also, don't really understand the requirements | vaguely-stated requirements of the OP. The way I'd like to see a question like this posted (and a way that'd be more likely to get useful responses IMHO) is something like:

c:\@Work\Perl\monks>perl -wMstrict -le "use Test::More 'no_plan'; use Test::NoWarnings; ;; use constant TEST_ACCEPT => qw( {12} {1b} {a2} {ab} {12_34} {1b_34} {a2_34} {ab_34} {12_3d} {1b_c4} {a2_cd} {aa_bb_cc_dd_ee} {a1_11_1c_bb} {aaa} {a} ); ;; use constant TEST_REJECT => qw( {a_bb_cc_dd_ee} {aaa_bb_cc_dd_ee} {1_11_1c_bb} {123_11_1c_bb} {aa_} {a_} {_aa} {_a} {1} {123} {abc1} {_} ); ;; my $rx_scored = qr{ [[:alnum:]]{2} (?: _ [[:alnum:]]{2})* }xms; my $rx_alphas = qr{ [[:alpha:]]+ }xms; ;; my $rx = qr{ \A \{ (?: $rx_scored | $rx_alphas) \} \z }xms; ;; note 'all to be accepted'; ;; for my $string (TEST_ACCEPT) { ok $string =~ $rx, qq{accept '$string'}; } ;; note 'all to be rejected'; ;; for my $string (TEST_REJECT) { ok $string !~ $rx, qq{reject '$string'}; } ;; done_testing; " # all to be accepted ok 1 - accept '{12}' ok 2 - accept '{1b}' ok 3 - accept '{a2}' ok 4 - accept '{ab}' ok 5 - accept '{12_34}' ok 6 - accept '{1b_34}' ok 7 - accept '{a2_34}' ok 8 - accept '{ab_34}' ok 9 - accept '{12_3d}' ok 10 - accept '{1b_c4}' ok 11 - accept '{a2_cd}' ok 12 - accept '{aa_bb_cc_dd_ee}' ok 13 - accept '{a1_11_1c_bb}' ok 14 - accept '{aaa}' ok 15 - accept '{a}' # all to be rejected ok 16 - reject '{a_bb_cc_dd_ee}' ok 17 - reject '{aaa_bb_cc_dd_ee}' ok 18 - reject '{1_11_1c_bb}' ok 19 - reject '{123_11_1c_bb}' ok 20 - reject '{aa_}' ok 21 - reject '{a_}' ok 22 - reject '{_aa}' ok 23 - reject '{_a}' ok 24 - reject '{1}' ok 25 - reject '{123}' ok 26 - reject '{abc1}' ok 27 - reject '{_}' 1..27 ok 28 - no warnings 1..28
Of course, one would omit the test regex or use a dummy in an initial query post.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Looking for a regular expression for the following pattern. by AnomalousMonk
in thread Looking for a regular expression for the following pattern. by skooma

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.