📌  相关文章
📜  Python正则表达式查找一个大写字母后跟小写字母的序列

📅  最后修改于: 2022-05-13 01:54:50.794000             🧑  作者: Mango

Python正则表达式查找一个大写字母后跟小写字母的序列

编写一个Python程序来查找一个大写字母后跟小写字母的序列。如果找到,则打印“是”,否则打印“否”。

例子:

Input : Geeks
Output : Yes

Input : geeksforgeeks
Output : No

方法:使用 re.search()

要检查一个大写字母后跟小写字母的序列,我们使用正则表达式' [AZ]+[az]+$ '。

# Python3 code to find sequences of one upper
# case letter followed by lower case letters
import re
  
# Function to match the string
def match(text):
          
        # regex
        pattern = '[A-Z]+[a-z]+$'
          
        # searching pattern
        if re.search(pattern, text):
                return('Yes')
        else:
                return('No')
  
# Driver Function
print(match("Geeks"))
print(match("geeksforGeeks"))
print(match("geeks"))

输出:

Yes
Yes
No