Octavian Rasnita wrote at Sun, 09 Jun 2002 08:42:34 +0200:

> Hi all,
> 
> I want to check if in a string there are more than 3 capital letters. I've tried 
>using:
> 
> if ($string=~ /[A-Z]{3,}/) {
> ....
> }
> }
> This match at least 3 capitals only if they are one after another. I want to check 
>if the string
> contains at least 3 capitals, doesn't matter how are they positioned.

David has shown you one way.
David's way becomes a little bit difficult 
if you'd want to look for 100 or so uppercase letters.

2 Another possibility is:

my @uppers = $string =~ /([A-Z])/g;
if (@uppers >= 3) {
    ...
}

or quite more beautiful (but is only possibible for characters:)

if ($string =~ tr/A-Z// >= 3) {
    ...
}


Best Wishes,
Janek

PS: BTW. This topic isn't really a cgi topic.
It should be better posted in perl.beginners.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to