Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Looking for a regular expression for the following pattern.

by AnomalousMonk (Bishop)
on Mar 29, 2018 at 14:33 UTC ( #1211980=note: print w/replies, xml ) Need Help??


in reply to Looking for a regular expression for the following pattern.

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:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1211980]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2022-08-15 04:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?