Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count uppercase letters in string using perl

I want to count the number of upper case letters in a string using perl.

For example: I need to know how many upper case characters the word "EeAEzzKUwUHZws" contains.

like image 546
yohan.jayarathna Avatar asked Jul 11 '11 15:07

yohan.jayarathna


People also ask

How do you count the number of special characters in a string?

Python program to count the number of special characters in a String. String contains 5 Special Character/s. First, we use For loop to iterate through the characters of the string. len(string) is used to count the number of characters which will then be used in the For loop as a parameter in the range function.

How can you tell if a string is uppercase or lowercase in shell script?

[^a-zA-Z0-9] means anything except for a-z , i.e. lowercase letters, A-Z , i.e. uppercase letters, and 0-9 , i.e. digits. sss , Sss , SSS all contain just letters, so they can't match. is true if the password contains any uppercase letter.

What is uppercase lowercase and special character?

Uppercase characters (A-Z) Lowercase characters (a-z) Digits (0-9) Special characters (~!


1 Answers

Beware of Unicode, as the straight A-Z thing isn't really portable for other characters, such as accented uppercase letters. if you need to handle these too, try:

my $result = 0;
$result++ while($string =~ m/\p{Uppercase}/g);
like image 155
Stuart Watt Avatar answered Sep 28 '22 04:09

Stuart Watt