Program to count uppercase, lowercase, special character and numeric value in the given string using Python

by | Jun 11, 2021 | Python Programs

Home » Python » Python Programs » Program to count uppercase, lowercase, special character and numeric value in the given string using Python

Introduction

The task is to find the occurrence of uppercase, lowercase, numeric value and special characters in the given input using regression.

Program to count uppercase, lowercase, special character and numeric value in the given string using Python

Program

import re
ip_str = input("Enter the string: ")
# Using re.findall()
ucase = re.findall(r"[A-Z]", ip_str)
lcase = re.findall(r"[a-z]", ip_str)
specialc = re.findall(r"[,.!?]", ip_str)
numc = re.findall(r"[0-9]", ip_str)


print("Uppercase character count: ", len(ucase))
print("Lowercase character count: ", len(lcase))
print("Special character count: ", len(specialc))
print("Numerical character count: ", len(numc))

Output

Program to count uppercase, lowercase, special character and numeric value in the given string Output

Explanation

The re.findall() has three arguments: pattern, input string, and flag = 0. In the above python code we have used re.findall() method to find all the matching patterns and return the values.

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author