I assumed the OP was just enumerating the possibilities ...

That's a good guess, and it's my guess too, but it's only a guess. Without reading too much between the lines (or the data records), I suspect it may have been stevieb's intention gently to make a point about ambiguity in the OP. (graff makes this point explicitly.)

... the one-line regex is not very "readable" no matter how you do it.

How about if you do it in a readable manner? I like the approach of factoring out regex sub-pattern elements. While more verbose, this eases maintenance, supports use of common elements for other data validation and extraction purposes, and is easily extended.

c:\@Work\Perl\monks>perl -wMstrict -le "my $na = qr{ N/A }xms; my $n = qr{ \d+ }xms; my $n_or_na = qr{ (?: $na | $n) \s+ }xms; my $test_name = qr{ [[:alpha:]] [_[:alpha:]]* }xms; ;; for my $str ( 'N/A 17497118 basic_mem_test 17036us FAIL 1', '17497118 N/A basic_mem_test 17036us FAIL 1', '17497118 17497118 basic_mem_test 17036us FAIL 1', 'N/A N/A basic_mem_test 17036us FAIL 1', 'foo 12345678 fake_mem_test 999us FAIL 1', '12345678 foo fake_mem_test 999us FAIL 1', 'foo foo fake_mem_test 999us FAIL 1', ) { print qq{'$str'}; if ($str =~ m{ \A \s* $n_or_na{2} ($test_name) }xms) { print qq{ match, grabbed '$1'}; } else { print ' NO match'; } } " 'N/A 17497118 basic_mem_test 17036us FAIL 1' match, grabbed 'basic_mem_test' '17497118 N/A basic_mem_test 17036us FAIL 1' match, grabbed 'basic_mem_test' '17497118 17497118 basic_mem_test 17036us FAIL 1' match, grabbed 'basic_mem_test' 'N/A N/A basic_mem_test 17036us FAIL 1' match, grabbed 'basic_mem_test' 'foo 12345678 fake_mem_test 999us FAIL 1' NO match '12345678 foo fake_mem_test 999us FAIL 1' NO match 'foo foo fake_mem_test 999us FAIL 1' NO match


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


In reply to Re^4: Regex not matching as expected by AnomalousMonk
in thread Regex not matching as expected by Fisherman166

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.