Re: regular expression
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Thu, 29 Dec 2005 10:47:34 -0800
Krishna.Thotakura@xxxxxxxxxxxxxxxx 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
.
- References:
- regular expression
- From: Krishna Thotakura
- regular expression
- Prev by Date: Re: search and replace a SQL query
- Next by Date: Re: graf-code
- Previous by thread: regular expression
- Next by thread: RE: regular expression
- Index(es):
Relevant Pages
|
|