Table of Contents
Introduction
The task is to find the occurrence of uppercase, lowercase, numeric value and special characters in the given input using regression.
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
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.
0 Comments