Although, i read about negated versions of lookahead and lookbehind operators, i didnt really understand how to use them. Now, i get it.
Thanks John. "John W. Krahn" <[EMAIL PROTECTED]> 12/29/2005 12:47 PM To: Perl Beginners <beginners@perl.org> cc: Subject: Re: regular expression [EMAIL PROTECTED] wrote: > I am looking for help on a PERL regular expression that can do the > following: > > 1. Make sure that the string is 20 chars or else match should fail. > 2. The string can have word characters or spaces or comma(,), hyphen(-), > ampersand(&) characters. > 3. If the string contains only spaces, then match should fail. > > Any ideas on how this can be done using just one regular expression ? This may do what you want: $ perl -le' my @array = ( q/ /, q/ab def,ghi-jkl&mn_pq/, q/abcdefghi^jklmnopqrs/, q/abcd/, q/abcdefghijklmnopqrstuvwxyz/, ); for ( @array ) { print "\047$_\047 is ", /\A(?!\s{20})[\w\s,&-]{20}\z/ ? "" : "NOT ", "valid"; } ' ' ' is NOT valid 'ab def,ghi-jkl&mn_pq' is valid 'abcdefghi^jklmnopqrs' is NOT valid 'abcd' is NOT valid 'abcdefghijklmnopqrstuvwxyz' is NOT valid John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> ************************************************************************* This communication, including attachments, is for the exclusive use of addressee and may contain proprietary, confidential and/or privileged information. If you are not the intended recipient, any use, copying, disclosure, dissemination or distribution is strictly prohibited. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this communication and destroy all copies. *************************************************************************