python使用正则表达式判别字符串是否以一个大写字符起始而跟随了一些小写字符

Posted Data+Science+Insight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python使用正则表达式判别字符串是否以一个大写字符起始而跟随了一些小写字符相关的知识,希望对你有一定的参考价值。

python使用正则表达式判别字符串是否以一个大写字符起始而跟随了一些小写字符
 

#

# 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("Darling"))
print(match("okseseesee"))
print(match("Bravo"))
print(match("B"))
Yes
No
Yes
No

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

参考: Python find sequences of one upper case letter followed by lower case letters

参考:python re

以上是关于python使用正则表达式判别字符串是否以一个大写字符起始而跟随了一些小写字符的主要内容,如果未能解决你的问题,请参考以下文章