Program to count uppercase, lowercase, special character and numeric values using Regex

import re

string = "Pythonforengineers !,* 12345"

uppercase_characters = re.findall(r"[A-Z]", string)

lowercase_characters = re.findall(r"[a-z]", string)

numerical_characters = re.findall(r"[0-9]", string)

special_characters = re.findall(r"[, .!?*]", string)

print("The no. of uppercase characters is", len(uppercase_characters))

print("The no. of lowercase characters is", len(lowercase_characters))

print("The no. of numerical characters is", len(numerical_characters))

print("The no. of special characters is", len(special_characters))


No comments: