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