如何检查字符串是否包含字母表中的任何字母? [英] How can I check if a string contains ANY letters from the alphabet?
本文介绍了如何检查字符串是否包含字母表中的任何字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
检查字符串是否包含字母表中的任何字母的最佳纯 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)
这篇关于如何检查字符串是否包含字母表中的任何字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文