Skip to content
Advertisement

How can I check if a string contains ANY letters from the alphabet?

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

Where string_1 would return False for having no letters of the alphabet in it and string_2 would return True for having letter.

Advertisement

Answer

Regex should be a fast approach:

re.search('[a-zA-Z]', the_string)
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement