Saturday, July 4, 2026
HomeLanguagesPython regex to find sequences of one upper case letter followed by...

Python regex to find sequences of one upper case letter followed by lower case letters

Write a Python Program to find sequences of one upper case letter followed by lower case letters. If found, print ‘Yes’, otherwise ‘No’.

Examples:

Input : Geeks
Output : Yes

Input : neveropen
Output : No

Python regex to find sequences of one upper case letter followed by lower case letters

Using re.search() To check if the sequence of one upper case letter followed by lower case letters we use regular expression ‘[A-Z]+[a-z]+$’. 

Python3




# your code goes here# Python program to
# find the most occurring element
import re
from collections import Counter
 
def most_occr_element(word):
     
    # re.findall will extract all the elements
    # from the string and make a list
    arr = re.findall(r'[0-9]+', word)   
     
    # to store maxm frequency
    maxm = 0
 
    # to store maxm element of most frequency
    max_elem = 0
     
    # counter will store all the number with
    # their frequencies
    # c = counter((55, 2), (2, 1), (3, 1), (4, 1))   
    c = Counter(arr)
     
    # Store all the keys of counter in a list in
    # which first would we our required element   
    for x in list(c.keys()):
 
        if c[x]>= maxm:
            maxm = c[x]
            max_elem = int(x)
                 
    return max_elem
 
# Driver program
if __name__ == "__main__":
    word = 'geek55of55gee4ksabc3dr2x'
    print(most_occr_element(word))


Output:

Yes
Yes
No

Time complexity: O(n), where n is length of string.
Auxiliary Space: O(1)

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12015 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6967 POSTS0 COMMENTS