Well, the first one's a forehead-smacker: of the strings, the only one that *SATISFIES* your first attempt at a fix (and hence is marked as valid) IS 12345z ("unless the string is five digits followed by one or more non-digits, mark it as invalid")
the second one says "match something that has five digits at the beginning *OR* which contains (somewhere) one or more non-digits. (i.e. the caret doesn't bind the \D to the beginning of the string. You'd have to use parentheses (perhaps memory-free) for that, e.g.:
/^(?:\d{5,}|\D+)/
I'd suggest changing the logic slightly, and I'll use the nifty ternary operator too:
foreach (@stuff) { my $status = ( /^\d{5,}$/ ) ? 'valid' : 'invalid'; print "$_ is $status\n"; }
HTH
Philosophy can be made out of anything. Or less -- Jerry A. Fodor
In reply to Re: Regex Pattern Problem
by arturo
in thread Regex Pattern Problem
by THRAK
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |