Another way to go using rubasov's data set plus a completely illegal line (ZA). The below is more "wordy" than other solutions, but I think what it does and how it does it is clear. If for example, RESULT=" " should be disallowed, there is a clear place to do that modification.
#!/usr/bin/perl -w use strict; while (<DATA>) { chomp; my $result = is_match($_); defined($result) ? print "$_:\tRESULT=\"$result\"\n" : print "$_:\tRESULT=NO MATCH\n"; } sub is_match { my $term = shift; my $inner = ($term =~ m/^A(.*)Z$/)[0]; return undef if (!defined($inner)); return $inner if $inner eq ""; return $inner if $inner =~ m/^\s/; return undef; } =prints: AZ: RESULT="" AZZ: RESULT=NO MATCH A SOMETHING Z: RESULT=" SOMETHING " ASOMETHINGZ: RESULT=NO MATCH A Z: RESULT=" " A ZZ: RESULT=" Z" AAZZ: RESULT=NO MATCH AA ZZ: RESULT=NO MATCH ZA: RESULT=NO MATCH =cut __DATA__ AZ AZZ A SOMETHING Z ASOMETHINGZ A Z A ZZ AAZZ AA ZZ ZA
Update: I looked at the OP's spec again and it appears that this tweaking of is_match() would be better?:
sub is_match { my $term = shift; my $inner = ($term =~ m/^A(.*)Z$/)[0]; return undef if (!defined($inner)); return undef if $inner eq ""; return $inner if $inner =~ m/^\s+\S/; return undef; } prints:..... AZ: RESULT=NO MATCH AZZ: RESULT=NO MATCH A SOMETHING Z: RESULT=" SOMETHING " ASOMETHINGZ: RESULT=NO MATCH A Z: RESULT=NO MATCH A ZZ: RESULT=" Z" AAZZ: RESULT=NO MATCH AA ZZ: RESULT=NO MATCH ZA: RESULT=NO MATCH

In reply to Re: This regexp made simpler by Marshall
in thread This regexp made simpler by rovf

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.