in reply to Re: This regexp made simpler
in thread This regexp made simpler

What should 'A ZZ', 'AAZZ' and 'AA ZZ' match? (added these as test cases)
They would (and should) not match at all...

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^3: This regexp made simpler
by FunkyMonk (Bishop) on Apr 25, 2010 at 11:31 UTC
    Updating my post to accommodate the anchors and your update:
    my @strings = ('AZ', 'A SOMETHING Z', 'ASOMETHINGZ', 'A Z', 'A ZZ', ' +AA ZZ', 'AAZZ', 'A Z'); for (@strings) { if (/^A( [^Z]*)?Z$/) { my $grabbed = $1 // ''; say "'$_' grabbed '$grabbed'"; } else { say "'$_' did not match" } } __END__ 'AZ' grabbed '' 'A SOMETHING Z' grabbed ' SOMETHING ' 'ASOMETHINGZ' did not match 'A Z' grabbed ' ' 'A ZZ' did not match 'AA ZZ' did not match 'AAZZ' did not match 'A Z' grabbed ' '


    Unless I state otherwise, all my code runs with strict and warnings
Re^3: This regexp made simpler
by FunkyMonk (Bishop) on Apr 25, 2010 at 11:23 UTC
    I should have taken more notice of the anchors in your OP :(