Python regex to find sequences of one upper case letter followed by lower case letters Last Updated : 06 Sep, 2024 Comments Improve Suggest changes Like Article Like Report 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 : GeeksOutput : YesInput : geeksforgeeksOutput : NoPython regex to find sequences of one upper case letter followed by lower case lettersUsing 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]+$'. Python import re def findSequence(text): # regex pattern pattern = '[A-Z][a-z]+' # Use re.search to find any match if re.search(pattern, text): return 'Yes' else: return 'No' # Driver program if __name__ == "__main__": word = 'geeAkAA55of55gee4ksabc3Ar2x' print(findSequence(word)) word = 'Geeks' print(findSequence(word)) word = 'geeksforgeeks' print(findSequence(word)) Output:YesYesNoTime complexity: O(n), where n is length of string.Auxiliary Space: O(1)Find those sequences of one upper case letter followed by lower case lettersTo find and print all sequences of one uppercase letter followed by lowercase letters in the given text we can use the re.findall() function. Here's how we can do it: Python import re def findSequences(text): #regex pattern pattern = r'[A-Z][a-z]+' return re.findall(pattern, text) # Driver program if __name__ == "__main__": word = 'geeAkAA55of55gee4ksabc3Ar2x' print(findSequences(word)) word = 'Geeks' print(findSequences(word)) word = 'geeksforgeeks' print(findSequences(word)) Output:['Ak', 'Ar']['Geeks'][]Time Complexity: O(n) where n is the length of the input text.Auxiliary Space Complexity: O(k) where k is the number of matches found. Comment More infoAdvertise with us Next Article Python regex to find sequences of one upper case letter followed by lower case letters S Smitha Dinesh Semwal Follow Improve Article Tags : Python Python Programs python-regex Python Regex-programs Practice Tags : python Similar Reads Python | Program that matches a word containing 'g' followed by one or more e's using regex Prerequisites : Regular Expressions | Set 1, Set 2 Given a string, the task is to check if that string contains any g followed by one or more e's in it, otherwise, print No match. Examples : Input : geeks for geeks Output : geeks geeks Input : graphic era Output : No match Approach : Firstly, make a 2 min read Verify that a string only contains letters, numbers, underscores and dashes - Python We are given a string and our task is to verify whether it contains only letters, numbers, underscores (_), and dashes (-). This kind of check is useful for validating usernames or formatted inputs. For example, a string like "G33ks_F0r-G3eks" should pass the validation, while a string like "Hello@1 2 min read Python program to check if a string has at least one letter and one number The task is to verify whether a given string contains both at least one letter (either uppercase or lowercase) and at least one number. For example, if the input string is "Hello123", the program should return True since it contains both letters and numbers. On the other hand, a string like "Hello" 3 min read Python program to check if lowercase letters exist in a string Checking for the presence of lowercase letters involves scanning the string and verifying if at least one character is a lowercase letter (from 'a' to 'z').Python provides simple and efficient ways to solve this problem using built-in string methods and constructs like loops and comprehensions.Using 2 min read Python | Ways to check if given string contains only letter Given a string, write a Python program to find whether a string contains only letters and no other keywords. Let's discuss a few methods to complete the task. Method #1: Using isalpha() method Python3 # Python code to demonstrate # to find whether string contains # only letters # Initialising string 3 min read Like