如何检查字符串是否包含字母表中的任何字母?
问题描述:
检查字符串是否包含字母表中的任何字母的最佳纯 Python 实现是什么?
What is best pure Python implementation to check if a string contains ANY letters from the alphabet?
string_1 = "(555).555-5555"
string_2 = "(555) 555 - 5555 ext. 5555
其中 string_1
将返回 False
因为其中没有字母,而 string_2
将返回 True
因为有信.
Where string_1
would return False
for having no letters of the alphabet in it and string_2
would return True
for having letter.
答
Regex 应该是一个快速的方法:
Regex should be a fast approach:
re.search('[a-zA-Z]', the_string)