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.
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.
[^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.
Uppercase characters (A-Z) Lowercase characters (a-z) Digits (0-9) Special characters (~!
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With