huck has shown why your regex (correctly!) matches a single space. Here's the approach I would take to a solution. (Note that I am sure there are CPAN modules to do all this much better!) Pay particular attention to adding test cases to the no-match section of tests. I would also add some mixed-case tests to the all-match section.

c:\@Work\Perl\monks>perl -wMstrict -le "use Test::More 'no_plan'; use Test::NoWarnings; ;; my $rx_1_3 = qr{ (?i) i{1,3} }xms; my $rx_1_9 = qr{ (?i) (?: $rx_1_3 | iv | v $rx_1_3? | ix) }xms; my $rx_1_39 = qr{ (?i) (?: $rx_1_9 | x{1,3} $rx_1_9?) }xms; ;; my $pat = qr{ [(]? \b $rx_1_39 \b (?: [.] | [)][.]?) [ ] }xms; ;; use constant ROMAN_1_39 => qw( i ii iii iv v vi vii viii ix x xi xii xiii xiv xv xvi xvii xviii xix xx xxi xxii xxiii xxiv xxv xxvi xxvii xxviii xxix xxx xxxi xxxii xxxiii xxxiv xxxv xxxvi xxxvii xxxviii xxxix ); ;; note 'perl version: ', $]; ;; my $test_regex = qr{ \A $pat \z }xms; note 'test regex: ', $test_regex; ;; note 'ALL must match'; for my $roman (ROMAN_1_39, map uc, ROMAN_1_39) { for my $pre ('', '(') { for my $post (qw/. ) )./) { my $rs = qq{$pre$roman$post }; ok $rs =~ $test_regex, qq{'$rs'}; } } } ;; note 'NONE shall pass!'; for my $nomatch (ROMAN_1_39, ' ', qw(iiii ixxxix xxxixi ixxxixi etc), ) { ok $nomatch !~ $test_regex, qq{'$nomatch'}; } ;; done_testing; "
(I won't pollute these sacred spaces with the rather tedious output.)


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


In reply to Re: Pattern Matching by AnomalousMonk
in thread Pattern Matching by davidas

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.